cast Double to String in java

Posted on October 26, 2007. Filed under: Java programming | Tags: , , , , , , |

Double to String casting …
if you want to display its String in number format (like this ###,###,##0.00) do not use these lines …


    Double sk = 12300000000.35;
    System.out.println(sk.toString());
    System.out.println(String.valueOf(sk));

they would result like these ones:

1.230000000035E10
1.230000000035E10

use this one instead.


    Double sk = 12300000000.35;
    NumberFormat nm = NumberFormat.getNumberInstance();

    System.out.println(nm.format(sk));

the latter result would be this:
12.300.000.000,35

Make a Comment

Make A Comment: ( 1 so far )

blockquote and a tags work here.

One Response to “cast Double to String in java”

RSS Feed for Ooh … Begitu! I see, I see … Comments RSS Feed

wow, excellently explained. This was Exactly what I was looking for. Thank you very much. Please keep it up. You have been very helpful.


Where's The Comment Form?

Liked it here?
Why not try sites on the blogroll...