Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33882
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: double-to-int conversion without a cast |
| Date | 2016-02-25 15:21 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <nan658$mg4$1@dont-email.me> (permalink) |
| References | <conversion-20160225020052@ram.dialup.fu-berlin.de> <nallb7$19k0$1@gioia.aioe.org> <namt0l$icf$1@dont-email.me> <20fc7234-8962-4b0d-962b-c1b5c6de17db@googlegroups.com> |
On Thu, 25 Feb 2016 05:36:06 -0800, Eric Douglas wrote:
> On Thursday, February 25, 2016 at 7:48:19 AM UTC-5, Martin Gregorie
> 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 |
>
> Those Math methods are best for simple conversion.
>
Yep. I was thinking of tasks like converting geographic coordinates
represented by decimal degrees held in a double into a string like
ddd mm'ss"X.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll 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