-3

I have a problem. My output is:

8.7E7

I want to set it to 87000000. What should I do?

public class Test {
    /**
     * @param args
     */

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        double num = 87000000;

        System.out.println("num = " + num);
    }
}
Qiu
  • 5,651
  • 10
  • 49
  • 56
Ahmad Budi U
  • 111
  • 1
  • 12

2 Answers2

1

Do:

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

This will print the double value with zero decimal places. See https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html for details on the formatting in printf.

If you want to use the String somewhere then use:

    String msg = String.format("num = %.0f", num);
Krzysztof Krasoń
  • 26,515
  • 16
  • 89
  • 115
0
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
    // TODO Auto-generated method stub
     double num = 87000000;

     System.out.printf("num = %.0f \n", num);
}}

Just change your System.out.println() to System.out.printf() and use the format specifier. The "\n” adds a new line.

For more details on how that works, just visit this link.

http://www.alvinalexander.com/programming/printf-format-cheat-sheet

Twahanz
  • 204
  • 1
  • 15