Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33880
| Path | csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: double-to-int conversion without a cast |
| Date | Thu, 25 Feb 2016 07:54:51 -0500 |
| Organization | A noiseless patient Spider |
| Lines | 32 |
| Message-ID | <namtdg$nik$1@dont-email.me> (permalink) |
| References | <conversion-20160225020052@ram.dialup.fu-berlin.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Thu, 25 Feb 2016 12:52:00 -0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="2d081e2f7155c28005d4472f67c2f43d"; logging-data="24148"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX181utu6Dk4qx3ye8hBJ9edB" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 |
| In-Reply-To | <conversion-20160225020052@ram.dialup.fu-berlin.de> |
| Cancel-Lock | sha1:uf0/1ZjZF4vUbAtkXQWYC3TVjA4= |
| Xref | csiph.com comp.lang.java.programmer:33880 |
Show key headers only | 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.
The Math.round() methods will do double to *long* or
*float* to int, but I don't know of a static double-to-int.
But here's a *really* ugly idea:
double d = ...;
int i = new Double(d).intValue();
Personally, I think you should show the class the (int) operator,
telling them "I'll explain this in a later lesson; for now, just
use it as shown and don't ask questions."
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
Back to comp.lang.java.programmer | Previous | Next | Find similar | Unroll thread
Re: double-to-int conversion without a cast Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-25 07:54 -0500
csiph-web