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


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

Re: double-to-int conversion without a cast

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: double-to-int conversion without a cast
Date 2016-02-24 20:28 -0500
Organization Aioe.org NNTP Server
Message-ID <nallb7$19k0$1@gioia.aioe.org> (permalink)
References <conversion-20160225020052@ram.dialup.fu-berlin.de>

Show all headers | View raw


On 2/24/2016 8:07 PM, Stefan Ram wrote:
>    At a point in my course, I have only introduced basic
>    arithmetic operations and calls of static methods and
>    the types »int«, »double«, and »java.lang.String«.
>
>    I already can show them how to convert from int to double
>    (»* 1.0«) or between the numbers and »java.lang.String«
>    (calling conversion methods from the Java SE standard
>    library).
>
>    But I am not aware of how to convert from double to int
>    with only the above means. The standard library is large.
>    Maybe there is a static method that takes a double and returns
>    it's floor or rounded value as an int and I am not aware of it?
>
>    I don't need this. I just ask for curiosity.

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));

Arne


Back to comp.lang.java.programmer | Previous | Next — 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