< prev index next >

src/java.base/share/classes/java/util/Formatter.java

Print this page




1212  *     value.
1213  *
1214  *     <p> Let <i>n</i> be the unique integer such that 10<sup><i>n</i></sup>
1215  *     &lt;= <i>m</i> &lt; 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the
1216  *     mathematically exact quotient of <i>m</i> and 10<sup><i>n</i></sup> so
1217  *     that 1 &lt;= <i>a</i> &lt; 10. The magnitude is then represented as the
1218  *     integer part of <i>a</i>, as a single decimal digit, followed by the
1219  *     decimal separator followed by decimal digits representing the fractional
1220  *     part of <i>a</i>, followed by the exponent symbol {@code 'e'}
1221  *     (<code>'\u0065'</code>), followed by the sign of the exponent, followed
1222  *     by a representation of <i>n</i> as a decimal integer, as produced by the
1223  *     method {@link Long#toString(long, int)}, and zero-padded to include at
1224  *     least two digits.
1225  *
1226  *     <p> The number of digits in the result for the fractional part of
1227  *     <i>m</i> or <i>a</i> is equal to the precision.  If the precision is not
1228  *     specified then the default value is {@code 6}. If the precision is less
1229  *     than the number of digits which would appear after the decimal point in
1230  *     the string returned by {@link Float#toString(float)} or {@link
1231  *     Double#toString(double)} respectively, then the value will be rounded
1232  *     using the {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
1233  *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
1234  *     For a canonical representation of the value, use {@link
1235  *     Float#toString(float)} or {@link Double#toString(double)} as
1236  *     appropriate.
1237  *
1238  *     <p>If the {@code ','} flag is given, then an {@link
1239  *     FormatFlagsConversionMismatchException} will be thrown.
1240  *
1241  * <tr><th scope="row" style="vertical-align:top"> {@code 'E'}
1242  *     <td style="vertical-align:top"> <code>'\u0045'</code>
1243  *     <td> The upper-case variant of {@code 'e'}.  The exponent symbol
1244  *     will be {@code 'E'} (<code>'\u0045'</code>).
1245  *
1246  * <tr><th scope="row" style="vertical-align:top"> {@code 'g'}
1247  *     <td style="vertical-align:top"> <code>'\u0067'</code>
1248  *     <td> Requires the output to be formatted in general scientific notation
1249  *     as described below. The <a href="#L10nAlgorithm">localization
1250  *     algorithm</a> is applied.
1251  *
1252  *     <p> After rounding for the precision, the formatting of the resulting


1281  *     <p> The result is a string that represents the sign and magnitude
1282  *     (absolute value) of the argument.  The formatting of the sign is
1283  *     described in the <a href="#L10nAlgorithm">localization
1284  *     algorithm</a>. The formatting of the magnitude <i>m</i> depends upon its
1285  *     value.
1286  *
1287  *     <p> If <i>m</i> NaN or infinite, the literal strings "NaN" or
1288  *     "Infinity", respectively, will be output.  These values are not
1289  *     localized.
1290  *
1291  *     <p> The magnitude is formatted as the integer part of <i>m</i>, with no
1292  *     leading zeroes, followed by the decimal separator followed by one or
1293  *     more decimal digits representing the fractional part of <i>m</i>.
1294  *
1295  *     <p> The number of digits in the result for the fractional part of
1296  *     <i>m</i> or <i>a</i> is equal to the precision.  If the precision is not
1297  *     specified then the default value is {@code 6}. If the precision is less
1298  *     than the number of digits which would appear after the decimal point in
1299  *     the string returned by {@link Float#toString(float)} or {@link
1300  *     Double#toString(double)} respectively, then the value will be rounded
1301  *     using the {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
1302  *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
1303  *     For a canonical representation of the value, use {@link
1304  *     Float#toString(float)} or {@link Double#toString(double)} as
1305  *     appropriate.
1306  *
1307  * <tr><th scope="row" style="vertical-align:top"> {@code 'a'}
1308  *     <td style="vertical-align:top"> <code>'\u0061'</code>
1309  *     <td> Requires the output to be formatted in hexadecimal exponential
1310  *     form.  No localization is applied.
1311  *
1312  *     <p> The result is a string that represents the sign and magnitude
1313  *     (absolute value) of the argument <i>x</i>.
1314  *
1315  *     <p> If <i>x</i> is negative or a negative-zero value then the result
1316  *     will begin with {@code '-'} (<code>'\u002d'</code>).
1317  *
1318  *     <p> If <i>x</i> is positive or a positive-zero value and the
1319  *     {@code '+'} flag is given then the result will begin with {@code '+'}
1320  *     (<code>'\u002b'</code>).
1321  *


1444  *     algorithm</a>. The formatting of the magnitude <i>m</i> depends upon its
1445  *     value.
1446  *
1447  *     <p> Let <i>n</i> be the unique integer such that 10<sup><i>n</i></sup>
1448  *     &lt;= <i>m</i> &lt; 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the
1449  *     mathematically exact quotient of <i>m</i> and 10<sup><i>n</i></sup> so
1450  *     that 1 &lt;= <i>a</i> &lt; 10. The magnitude is then represented as the
1451  *     integer part of <i>a</i>, as a single decimal digit, followed by the
1452  *     decimal separator followed by decimal digits representing the fractional
1453  *     part of <i>a</i>, followed by the exponent symbol {@code 'e'}
1454  *     (<code>'\u0065'</code>), followed by the sign of the exponent, followed
1455  *     by a representation of <i>n</i> as a decimal integer, as produced by the
1456  *     method {@link Long#toString(long, int)}, and zero-padded to include at
1457  *     least two digits.
1458  *
1459  *     <p> The number of digits in the result for the fractional part of
1460  *     <i>m</i> or <i>a</i> is equal to the precision.  If the precision is not
1461  *     specified then the default value is {@code 6}.  If the precision is
1462  *     less than the number of digits to the right of the decimal point then
1463  *     the value will be rounded using the
1464  *     {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
1465  *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
1466  *     For a canonical representation of the value, use {@link
1467  *     BigDecimal#toString()}.
1468  *
1469  *     <p> If the {@code ','} flag is given, then an {@link
1470  *     FormatFlagsConversionMismatchException} will be thrown.
1471  *
1472  * <tr><th scope="row" style="vertical-align:top"> {@code 'E'}
1473  *     <td style="vertical-align:top"> <code>'\u0045'</code>
1474  *     <td> The upper-case variant of {@code 'e'}.  The exponent symbol
1475  *     will be {@code 'E'} (<code>'\u0045'</code>).
1476  *
1477  * <tr><th scope="row" style="vertical-align:top"> {@code 'g'}
1478  *     <td style="vertical-align:top"> <code>'\u0067'</code>
1479  *     <td> Requires the output to be formatted in general scientific notation
1480  *     as described below. The <a href="#L10nAlgorithm">localization
1481  *     algorithm</a> is applied.
1482  *
1483  *     <p> After rounding for the precision, the formatting of the resulting
1484  *     magnitude <i>m</i> depends on its value.


1507  *     <td style="vertical-align:top"> <code>'\u0066'</code>
1508  *     <td> Requires the output to be formatted using <a id="bdecimal">decimal
1509  *     format</a>.  The <a href="#L10nAlgorithm">localization algorithm</a> is
1510  *     applied.
1511  *
1512  *     <p> The result is a string that represents the sign and magnitude
1513  *     (absolute value) of the argument.  The formatting of the sign is
1514  *     described in the <a href="#L10nAlgorithm">localization
1515  *     algorithm</a>. The formatting of the magnitude <i>m</i> depends upon its
1516  *     value.
1517  *
1518  *     <p> The magnitude is formatted as the integer part of <i>m</i>, with no
1519  *     leading zeroes, followed by the decimal separator followed by one or
1520  *     more decimal digits representing the fractional part of <i>m</i>.
1521  *
1522  *     <p> The number of digits in the result for the fractional part of
1523  *     <i>m</i> or <i>a</i> is equal to the precision. If the precision is not
1524  *     specified then the default value is {@code 6}.  If the precision is
1525  *     less than the number of digits to the right of the decimal point
1526  *     then the value will be rounded using the
1527  *     {@linkplain java.math.BigDecimal#ROUND_HALF_UP round half up
1528  *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
1529  *     For a canonical representation of the value, use {@link
1530  *     BigDecimal#toString()}.
1531  *
1532  * </tbody>
1533  * </table>
1534  *
1535  * <p> All <a href="#intFlags">flags</a> defined for Byte, Short, Integer, and
1536  * Long apply.
1537  *
1538  * <p> If the {@code '#'} flag is given, then the decimal separator will
1539  * always be present.
1540  *
1541  * <p> The <a href="#floatdFlags">default behavior</a> when no flags are
1542  * given is the same as for Float and Double.
1543  *
1544  * <p> The specification of <a href="#floatDWidth">width</a> and <a
1545  * href="#floatDPrec">precision</a> is the same as defined for Float and
1546  * Double.
1547  *




1212  *     value.
1213  *
1214  *     <p> Let <i>n</i> be the unique integer such that 10<sup><i>n</i></sup>
1215  *     &lt;= <i>m</i> &lt; 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the
1216  *     mathematically exact quotient of <i>m</i> and 10<sup><i>n</i></sup> so
1217  *     that 1 &lt;= <i>a</i> &lt; 10. The magnitude is then represented as the
1218  *     integer part of <i>a</i>, as a single decimal digit, followed by the
1219  *     decimal separator followed by decimal digits representing the fractional
1220  *     part of <i>a</i>, followed by the exponent symbol {@code 'e'}
1221  *     (<code>'\u0065'</code>), followed by the sign of the exponent, followed
1222  *     by a representation of <i>n</i> as a decimal integer, as produced by the
1223  *     method {@link Long#toString(long, int)}, and zero-padded to include at
1224  *     least two digits.
1225  *
1226  *     <p> The number of digits in the result for the fractional part of
1227  *     <i>m</i> or <i>a</i> is equal to the precision.  If the precision is not
1228  *     specified then the default value is {@code 6}. If the precision is less
1229  *     than the number of digits which would appear after the decimal point in
1230  *     the string returned by {@link Float#toString(float)} or {@link
1231  *     Double#toString(double)} respectively, then the value will be rounded
1232  *     using the {@linkplain java.math.RoundingMode#HALF_UP round half up
1233  *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
1234  *     For a canonical representation of the value, use {@link
1235  *     Float#toString(float)} or {@link Double#toString(double)} as
1236  *     appropriate.
1237  *
1238  *     <p>If the {@code ','} flag is given, then an {@link
1239  *     FormatFlagsConversionMismatchException} will be thrown.
1240  *
1241  * <tr><th scope="row" style="vertical-align:top"> {@code 'E'}
1242  *     <td style="vertical-align:top"> <code>'\u0045'</code>
1243  *     <td> The upper-case variant of {@code 'e'}.  The exponent symbol
1244  *     will be {@code 'E'} (<code>'\u0045'</code>).
1245  *
1246  * <tr><th scope="row" style="vertical-align:top"> {@code 'g'}
1247  *     <td style="vertical-align:top"> <code>'\u0067'</code>
1248  *     <td> Requires the output to be formatted in general scientific notation
1249  *     as described below. The <a href="#L10nAlgorithm">localization
1250  *     algorithm</a> is applied.
1251  *
1252  *     <p> After rounding for the precision, the formatting of the resulting


1281  *     <p> The result is a string that represents the sign and magnitude
1282  *     (absolute value) of the argument.  The formatting of the sign is
1283  *     described in the <a href="#L10nAlgorithm">localization
1284  *     algorithm</a>. The formatting of the magnitude <i>m</i> depends upon its
1285  *     value.
1286  *
1287  *     <p> If <i>m</i> NaN or infinite, the literal strings "NaN" or
1288  *     "Infinity", respectively, will be output.  These values are not
1289  *     localized.
1290  *
1291  *     <p> The magnitude is formatted as the integer part of <i>m</i>, with no
1292  *     leading zeroes, followed by the decimal separator followed by one or
1293  *     more decimal digits representing the fractional part of <i>m</i>.
1294  *
1295  *     <p> The number of digits in the result for the fractional part of
1296  *     <i>m</i> or <i>a</i> is equal to the precision.  If the precision is not
1297  *     specified then the default value is {@code 6}. If the precision is less
1298  *     than the number of digits which would appear after the decimal point in
1299  *     the string returned by {@link Float#toString(float)} or {@link
1300  *     Double#toString(double)} respectively, then the value will be rounded
1301  *     using the {@linkplain java.math.RoundingMode#HALF_UP round half up
1302  *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
1303  *     For a canonical representation of the value, use {@link
1304  *     Float#toString(float)} or {@link Double#toString(double)} as
1305  *     appropriate.
1306  *
1307  * <tr><th scope="row" style="vertical-align:top"> {@code 'a'}
1308  *     <td style="vertical-align:top"> <code>'\u0061'</code>
1309  *     <td> Requires the output to be formatted in hexadecimal exponential
1310  *     form.  No localization is applied.
1311  *
1312  *     <p> The result is a string that represents the sign and magnitude
1313  *     (absolute value) of the argument <i>x</i>.
1314  *
1315  *     <p> If <i>x</i> is negative or a negative-zero value then the result
1316  *     will begin with {@code '-'} (<code>'\u002d'</code>).
1317  *
1318  *     <p> If <i>x</i> is positive or a positive-zero value and the
1319  *     {@code '+'} flag is given then the result will begin with {@code '+'}
1320  *     (<code>'\u002b'</code>).
1321  *


1444  *     algorithm</a>. The formatting of the magnitude <i>m</i> depends upon its
1445  *     value.
1446  *
1447  *     <p> Let <i>n</i> be the unique integer such that 10<sup><i>n</i></sup>
1448  *     &lt;= <i>m</i> &lt; 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the
1449  *     mathematically exact quotient of <i>m</i> and 10<sup><i>n</i></sup> so
1450  *     that 1 &lt;= <i>a</i> &lt; 10. The magnitude is then represented as the
1451  *     integer part of <i>a</i>, as a single decimal digit, followed by the
1452  *     decimal separator followed by decimal digits representing the fractional
1453  *     part of <i>a</i>, followed by the exponent symbol {@code 'e'}
1454  *     (<code>'\u0065'</code>), followed by the sign of the exponent, followed
1455  *     by a representation of <i>n</i> as a decimal integer, as produced by the
1456  *     method {@link Long#toString(long, int)}, and zero-padded to include at
1457  *     least two digits.
1458  *
1459  *     <p> The number of digits in the result for the fractional part of
1460  *     <i>m</i> or <i>a</i> is equal to the precision.  If the precision is not
1461  *     specified then the default value is {@code 6}.  If the precision is
1462  *     less than the number of digits to the right of the decimal point then
1463  *     the value will be rounded using the
1464  *     {@linkplain java.math.RoundingMode#HALF_UP round half up
1465  *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
1466  *     For a canonical representation of the value, use {@link
1467  *     BigDecimal#toString()}.
1468  *
1469  *     <p> If the {@code ','} flag is given, then an {@link
1470  *     FormatFlagsConversionMismatchException} will be thrown.
1471  *
1472  * <tr><th scope="row" style="vertical-align:top"> {@code 'E'}
1473  *     <td style="vertical-align:top"> <code>'\u0045'</code>
1474  *     <td> The upper-case variant of {@code 'e'}.  The exponent symbol
1475  *     will be {@code 'E'} (<code>'\u0045'</code>).
1476  *
1477  * <tr><th scope="row" style="vertical-align:top"> {@code 'g'}
1478  *     <td style="vertical-align:top"> <code>'\u0067'</code>
1479  *     <td> Requires the output to be formatted in general scientific notation
1480  *     as described below. The <a href="#L10nAlgorithm">localization
1481  *     algorithm</a> is applied.
1482  *
1483  *     <p> After rounding for the precision, the formatting of the resulting
1484  *     magnitude <i>m</i> depends on its value.


1507  *     <td style="vertical-align:top"> <code>'\u0066'</code>
1508  *     <td> Requires the output to be formatted using <a id="bdecimal">decimal
1509  *     format</a>.  The <a href="#L10nAlgorithm">localization algorithm</a> is
1510  *     applied.
1511  *
1512  *     <p> The result is a string that represents the sign and magnitude
1513  *     (absolute value) of the argument.  The formatting of the sign is
1514  *     described in the <a href="#L10nAlgorithm">localization
1515  *     algorithm</a>. The formatting of the magnitude <i>m</i> depends upon its
1516  *     value.
1517  *
1518  *     <p> The magnitude is formatted as the integer part of <i>m</i>, with no
1519  *     leading zeroes, followed by the decimal separator followed by one or
1520  *     more decimal digits representing the fractional part of <i>m</i>.
1521  *
1522  *     <p> The number of digits in the result for the fractional part of
1523  *     <i>m</i> or <i>a</i> is equal to the precision. If the precision is not
1524  *     specified then the default value is {@code 6}.  If the precision is
1525  *     less than the number of digits to the right of the decimal point
1526  *     then the value will be rounded using the
1527  *     {@linkplain java.math.RoundingMode#HALF_UP round half up
1528  *     algorithm}.  Otherwise, zeros may be appended to reach the precision.
1529  *     For a canonical representation of the value, use {@link
1530  *     BigDecimal#toString()}.
1531  *
1532  * </tbody>
1533  * </table>
1534  *
1535  * <p> All <a href="#intFlags">flags</a> defined for Byte, Short, Integer, and
1536  * Long apply.
1537  *
1538  * <p> If the {@code '#'} flag is given, then the decimal separator will
1539  * always be present.
1540  *
1541  * <p> The <a href="#floatdFlags">default behavior</a> when no flags are
1542  * given is the same as for Float and Double.
1543  *
1544  * <p> The specification of <a href="#floatDWidth">width</a> and <a
1545  * href="#floatDPrec">precision</a> is the same as defined for Float and
1546  * Double.
1547  *


< prev index next >