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: Thu, 25 Feb 2016 15:21:12 -0000 (UTC) Organization: A noiseless patient Spider Lines: 35 Message-ID: References: <20fc7234-8962-4b0d-962b-c1b5c6de17db@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Thu, 25 Feb 2016 15:21:12 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="e5160e2be48f1ea550cf61512446f525"; logging-data="23044"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19M0PL7a6ZopIrVDgggYsUC4EXo13YC5Jw=" User-Agent: Pan/0.140 (Chocolate Salty Balls; GIT 3663720 git://git.gnome.org/pan2) Cancel-Lock: sha1:GIvPJRrJG1HcTqqEFFsFZR+iAYo= Xref: csiph.com comp.lang.java.programmer:33882 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 |