Formatting of integers and floating point values can be done using
%d and %f respectively. For formatting floating point values in scientific notation we can use %e . We can use %g format if we want the shortest of '%f' or '%e'.
Formatting Numbers Demo CODE import java.util.*; OUTPUT 1000.00 100000 1.00000e+07 1.00000e+09 DESCRIPTION Formatting the floating point types and print them in shortest form can be done using '%g' as shown above. Initially it uses '%f' for formatting, but as the size increases, it switches to '%e' for printing.
THINGS TO TRY
|