Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33879

Re: double-to-int conversion without a cast

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: double-to-int conversion without a cast
Date Thu, 25 Feb 2016 12:45:09 -0000 (UTC)
Organization A noiseless patient Spider
Lines 22
Message-ID <namt0l$icf$1@dont-email.me> (permalink)
References <conversion-20160225020052@ram.dialup.fu-berlin.de> <nallb7$19k0$1@gioia.aioe.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Injection-Date Thu, 25 Feb 2016 12:45:09 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="e5160e2be48f1ea550cf61512446f525"; logging-data="18831"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18AvgSg11FTQF2ZRbhOTdWj3ab197CCaOA="
User-Agent Pan/0.140 (Chocolate Salty Balls; GIT 3663720 git://git.gnome.org/pan2)
Cancel-Lock sha1:GMY6uDHyqUT/o+36iDbHaE4VdwU=
Xref csiph.com comp.lang.java.programmer:33879

Show key headers only | View raw


On Wed, 24 Feb 2016 20:28:05 -0500, Arne Vajhøj wrote:

> 
> Math.round(double) return long. And I do think it makes sense for it to
> return long and not int.
> 
> I am not aware of any good conversions.
> 
> If you are willing to take an ugly one then:
> 
> v = Integer.parseInt(String.format("%.0f", x));
> 
What Arne says.

However it may also be worth telling them about using the Math.floor() 
and Math.ceil() functions in conjunction with Math.round() because there 
are some situations when round() by itself won't do what you want.   

-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: double-to-int conversion without a cast Arne Vajhøj <arne@vajhoej.dk> - 2016-02-24 20:28 -0500
  Re: double-to-int conversion without a cast Martin Gregorie <martin@address-in-sig.invalid> - 2016-02-25 12:45 +0000
    Re: double-to-int conversion without a cast Eric Douglas <e.d.programmer@gmail.com> - 2016-02-25 05:36 -0800
      Re: double-to-int conversion without a cast Martin Gregorie <martin@address-in-sig.invalid> - 2016-02-25 15:21 +0000

csiph-web