programming-examples/java/Core_Java/Formatting real number with Decimal.java
2019-11-15 12:59:38 +01:00

15 lines
473 B
Java

Formatting real number with Decimal
import java.text.*;
public class NumFormat {
public static void main (String[] args) {
DecimalFormat science = new DecimalFormat("0.000E0");
DecimalFormat plain = new DecimalFormat("0.0000");
for(double d=100.0; d<140.0; d*=1.10) {
System.out.println("Scientific: " + science.format(d) +
" and Plain: " + plain.format(d));
}
}
}