Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: double-to-int conversion without a cast Date: Fri, 3 Jun 2016 10:53:17 -0000 (UTC) Organization: A noiseless patient Spider Lines: 29 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Fri, 3 Jun 2016 10:53:17 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="e5160e2be48f1ea550cf61512446f525"; logging-data="27596"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18aFWQZXgO6bCxqWunyddmPJWyu3L71dVY=" User-Agent: Pan/0.140 (Chocolate Salty Balls; GIT 3663720 git://git.gnome.org/pan2) Cancel-Lock: sha1:YOy62kPgm8hWet3nTDDVI4iLLLc= Xref: csiph.com comp.lang.java.programmer:34452 On Thu, 02 Jun 2016 22:18:13 -0700, Roedy Green wrote: > On 25 Feb 2016 01:07:44 GMT, ram@zedat.fu-berlin.de (Stefan Ram) > wrote: > >>ouble to int >> with only the above means > > I asked the conversion amanusensis at > http://mindprod.com/applet/converter.html > > it offered: > > // to int i from double d // best i = (int)d; > // or i = (int)Math.round(d); > // or i = (int)Math.ceil(d); > // or i = (int)Math.floor(d); This works: int n = new Long(Math.round(d)).intValue(); Look Ma, no casts! -- martin@ | Martin Gregorie gregorie. | Essex, UK org |