-3

How can I print a double in standard notation?

double h = 104857600 - 32;
System.out.println(h);

Result:

1.04857568E8

Desired result:

104857568
FThompson
  • 28,352
  • 13
  • 60
  • 93
Ridzuan Adris
  • 1,192
  • 2
  • 13
  • 32
  • 1
    usually, absolute value is something else (i.e. `abs(-2) = 2`), can you explain a little more –  Mar 20 '14 at 06:42
  • I think he means absolute value in a sense, readable number i.e not in (number)E(power) – Jay Dharmendra Solanki Mar 20 '14 at 06:44
  • I found another link on Stack Overflow for your reference. http://stackoverflow.com/questions/1631091/java-double-to-string-conversion-without-formatting Please mark the question as answered if the last reply helped you. Thanks. – Amal Gupta Mar 20 '14 at 06:55

1 Answers1

6

You can use printf()

System.out.printf("%.0f", h);

The 0 is the precision, you can modify it.

Edit:

If you want to store it as a String, you can use String.format("%.0f", h).

Christian Tapia
  • 33,620
  • 7
  • 56
  • 73
  • 1
    dear @Christian, thank you it work, but how can i store the absolute value in string variable? – Ridzuan Adris Mar 20 '14 at 06:47
  • 2
    @user2818462 Please stop referring to this as the absolute value. [Absolute value](http://en.wikipedia.org/wiki/Absolute_value) is something entirely different. – FThompson Mar 20 '14 at 06:47
  • What do you mean by *absolute value*? There is a method `String.format()`, that works like `printf()`. – Christian Tapia Mar 20 '14 at 06:50