Friday, 7 June 2019

Java: Print float value without scientific notation


App.java
package com.sample.app;

public class App {

 public static void main(String args[]) {

  float value = 12345670;
  System.out.println("value: " + value);

 }
}

Output
value: 1.234567E7

As you see the output of the program, ‘System.out.println’ method prints the value of a float in scientific notation. If you want to print the value without scientific notation use ‘System.out.printf’ method.

System.out.printf("value: %f\n", value);


App.java
package com.sample.app;

public class App {

 public static void main(String args[]) {

  float value = 12345670;
  System.out.println("value: " + value);
  System.out.printf("value: %f\n", value);

 }
}

Output
value: 1.234567E7

value: 12345670.000000


You may like

No comments:

Post a Comment