Zoo tutorials: [ SQL | Linux | XML ]
ProgZoo: [ Java | C# | VB | C++ | Perl ]
Log in

A Gentle Introduction to
Java Programming

Formatting Floating Point Values

 

Input and Output

Formatting Floating Point Values

1. [ Java ] Printing a decimal values


Big

The printf method takes a format string as the first parameter. This string is printed but the parameters that follow replace the % placeholders.

%f is used for floating point values.

Format Code Meaning
Simple %fThe default format
Fixed decimal places %.3f Print three decimal places.
Right justified %8.3Print right aligned in 8 characters. Use three decimal places.