DoubleFormat is a class for formatting numbers of type
Double.
The format is specified using two numbers:
maxPositions,
which is the maximum number of characters in the formatted output, and
numDigits, which is the desired number of significant digits
in the formatted output. The output may contain both fewer and more
significant digits than
numDigits, but
maxPositions
will always be honored. Some examples:
(maxPositions,numDigits) | (6,3) | (8,4) | (11,5) |
1.23456E-123 | 0.### | 1.E-123 | 1.234E-123 |
1.23456E-6 | 1.E-3 | 1.23E-6 | 1.2346E-3 |
0.123456 | 0.123 | 0.1234 | 0.12346 |
123.456 | 123. | 123.4 | 123.46 |
12345.6 | 1.E+4 | 12346. | 12346. |
1.23456E+8 | ##### | 1.23E+6 | 1.2346E+6 |
As can be seen from the examples, if
maxPositions is small
and the number to be formatted is very large or very small, then there
is no way to show the number and keep the significance. In that case
a sequence of hash marks (#) is shown instead. This can only occur if
maxPositions < 8.