Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35910
| From | Lothar Kimmeringer <news200709@kimmeringer.de> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: "Double.toString" |
| Date | 2016-11-20 22:49 +0100 |
| Organization | Organization?! Only chaos here! |
| Message-ID | <1u072gaozj278$.dlg@kimmeringer.de> (permalink) |
| References | <Double-toString-20161119164723@ram.dialup.fu-berlin.de> <o0s8u2$rj6$1@dont-email.me> |
Eric Sosman wrote:
> I wouldn't say "prominent," simply because I don't use it much:
> Whenever I want Java's string version of a double, I usually want it
> in combination with another string. So I write
>
> System.out.println("\u03c0 \u2248 " + Math.PI);
>
> ... and let Java fill in the toString() method call.
The resulting code being created by the compiler is quite
more complicated with this rather than doing
Double.toString(Math.PI). Your example isn't that bad, but
the most common way to create a String from a double
myString = "" + myDoubleValue
results in something like this:
myString = new StringBuilder()
.append("")
.append(String.valueOf(myDoubleValue)
.toString();
The number of objects being created is way higher than when
simply calling Double.toString(myDoubleValue). I read about
that in an article once and used the toString()-methods
ever since (makes code more readable IMHO as well).
Cheers, Lothar
--
Lothar Kimmeringer E-Mail: spamfang@kimmeringer.de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
Always remember: The answer is forty-two, there can only be wrong
questions!
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: "Double.toString" Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-11-20 08:37 -0500
Re: "Double.toString" Lothar Kimmeringer <news200709@kimmeringer.de> - 2016-11-20 22:49 +0100
Re: "Double.toString" Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-11-21 08:25 -0500
Re: "Double.toString" lewbloch@gmail.com - 2016-11-22 15:10 -0800
Re: "Double.toString" Lothar Kimmeringer <news200709@kimmeringer.de> - 2016-11-24 14:07 +0100
Re: "Double.toString" Arne Vajhøj <arne@vajhoej.dk> - 2016-11-24 11:12 -0500
Re: "Double.toString" lewbloch@gmail.com - 2016-11-27 08:16 -0800
Re: "Double.toString" Eric Douglas <e.d.programmer@gmail.com> - 2016-11-28 05:34 -0800
csiph-web