DoubleFormat
The datatype used for specifying the printing format of a Double variable.
DoubleFormat dfmt = "+5.3f" print "(", $format_double($dfmt, 3.14159265), ")"This produces the following output:
( +3.142)
$format_double()
function.
Example command | Output | Explanation of the format |
---|---|---|
print $format_double(".3f", 54.27305555) | 54.273 | Print the integer part plus 3 decimal places |
print $format_double(".3g", 54.27305555) | 54.3 | Print 3 significant figures of the number |
print $format_double(".1s", 54.27305555) | 54:16:23.0 | Print in sexagesimal (base 60) with 1 decimal place |
[flags][width][.precision]style
As shown, the specification optionally starts with any combination of the following flag characters.
Flag character | Meaning |
---|---|
"- " |
Left justify the printed number within the specified field width |
"+ " |
Always prefix the number with its sign. |
" " |
(space) If the number is positive and the " + "
flag is absent, prefix the number with a space. |
"# " |
Always display a decimal point even if no fraction digit follows it, and don't strip off trailing zeros. |
"0 " |
(zero) If the specified field width is greater than the amount of space needed to print the number, and the " - " flag has not been specified,
precede the number with sufficient spaces to make the
printed number have this width. |
After the optional flags, is an optional integer minimum field
width. This indicates the minimum number of characters that should
be used to print the number. If this is wider than the space needed
to print the number, then the number is by default padded with
leading spaces to make it occupy the specified width. However if
the "0
" flag is specified, then it is padded
with leading zeroes, unless the "-
" flag is
also specified, which causes it to be padded with trailing spaces.
The next optional component is the precision, which is indicated by a decimal point, followed by an integer. The meaning of this number differs depending on the printing style. See the table below.
The final component of format specifier is a character that indicates the printing style. This is the only non-optional component of the specifier. It must be one of the following.
Style character | Meaning |
---|---|
"f " |
Print the integer part of the number, followed by a decimal point, followed by the number of fractional digits specified by the precision. The default precision when not given is usually 6. |
"e " |
Use power-of-ten exponential notation, like 2.3e+05, to print the number. The precision specifies the number of decimal places to display in the mantissa, and usually defaults to 6. |
"g " |
Use either the "f " or the
"e " format, depending on the size of
the number to be printed. The precision indicates the number
of significant figures to be printed, and usually defaults
to 6.
|
"s " |
Print the number is sexagesimal (base 60) format, like +34:12:54.23. The precision indicates the number of fraction digits to displace in the final seconds field, and defaults to zero. |