Floating Point Output

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Answer:

Again, that depends on where you are. Some possible choices are

12,345.6789
12.345,6789
12 345,6789

Some countries use a decimal point to separate the integer part of a number from the fractional part, others use a comma.

Floating Point Output

The default locale determines how DecimalFormat.format() formats a floating point number. Here is a program that shows this.

import java.text.*;

class IODemoFloat
{
  public static void main ( String[] args )
  {
    double value = 12345.6789 ;    
    DecimalFormat numform = new DecimalFormat(); 
    System.out.println( "value = " + numform.format(value) );
  }
}

The output (on my computer) is:

value = 12,345.679

Notice that the output value has been rounded and shows three places to the right of the decimal.

QUESTION 5:

Has the contents of the variable value been changed by format()?