< prev index next >

src/java.base/share/classes/java/text/DecimalFormat.java

Print this page




 155  * 1,0000,0000.  If you supply a pattern with multiple grouping characters, the
 156  * interval between the last one and the end of the integer is the one that is
 157  * used. So <code>"#,##,###,####"</code> == <code>"######,####"</code> ==
 158  * <code>"##,####,####"</code>.
 159  *
 160  * <h4>Special Pattern Characters</h4>
 161  *
 162  * <p>Many characters in a pattern are taken literally; they are matched during
 163  * parsing and output unchanged during formatting.  Special characters, on the
 164  * other hand, stand for other characters, strings, or classes of characters.
 165  * They must be quoted, unless noted otherwise, if they are to appear in the
 166  * prefix or suffix as literals.
 167  *
 168  * <p>The characters listed here are used in non-localized patterns.  Localized
 169  * patterns use the corresponding characters taken from this formatter's
 170  * <code>DecimalFormatSymbols</code> object instead, and these characters lose
 171  * their special status.  Two exceptions are the currency sign and quote, which
 172  * are not localized.
 173  *
 174  * <blockquote>
 175  * <table border=0 cellspacing=3 cellpadding=0 summary="Chart showing symbol,
 176  *  location, localized, and meaning.">
 177  *     <tr style="background-color: rgb(204, 204, 255);">

 178  *          <th style="text-align:left">Symbol
 179  *          <th style="text-align:left">Location
 180  *          <th style="text-align:left">Localized?
 181  *          <th style="text-align:left">Meaning


 182  *     <tr style="vertical-align:top">
 183  *          <td><code>0</code>
 184  *          <td>Number
 185  *          <td>Yes
 186  *          <td>Digit
 187  *     <tr style="vertical-align: top; background-color: rgb(238, 238, 255);">
 188  *          <td><code>#</code>
 189  *          <td>Number
 190  *          <td>Yes
 191  *          <td>Digit, zero shows as absent
 192  *     <tr style="vertical-align:top">
 193  *          <td><code>.</code>
 194  *          <td>Number
 195  *          <td>Yes
 196  *          <td>Decimal separator or monetary decimal separator
 197  *     <tr style="vertical-align: top; background-color: rgb(238, 238, 255);">
 198  *          <td><code>-</code>
 199  *          <td>Number
 200  *          <td>Yes
 201  *          <td>Minus sign
 202  *     <tr style="vertical-align:top">
 203  *          <td><code>,</code>
 204  *          <td>Number
 205  *          <td>Yes
 206  *          <td>Grouping separator
 207  *     <tr style="vertical-align: top; background-color: rgb(238, 238, 255);">
 208  *          <td><code>E</code>
 209  *          <td>Number
 210  *          <td>Yes
 211  *          <td>Separates mantissa and exponent in scientific notation.
 212  *              <em>Need not be quoted in prefix or suffix.</em>
 213  *     <tr style="vertical-align:top">
 214  *          <td><code>;</code>
 215  *          <td>Subpattern boundary
 216  *          <td>Yes
 217  *          <td>Separates positive and negative subpatterns
 218  *     <tr style="vertical-align: top; background-color: rgb(238, 238, 255);">
 219  *          <td><code>%</code>
 220  *          <td>Prefix or suffix
 221  *          <td>Yes
 222  *          <td>Multiply by 100 and show as percentage
 223  *     <tr style="vertical-align:top">
 224  *          <td><code>\u2030</code>
 225  *          <td>Prefix or suffix
 226  *          <td>Yes
 227  *          <td>Multiply by 1000 and show as per mille value
 228  *     <tr style="vertical-align: top; background-color: rgb(238, 238, 255);">
 229  *          <td><code>¤</code> (<code>\u00A4</code>)
 230  *          <td>Prefix or suffix
 231  *          <td>No
 232  *          <td>Currency sign, replaced by currency symbol.  If
 233  *              doubled, replaced by international currency symbol.
 234  *              If present in a pattern, the monetary decimal separator
 235  *              is used instead of the decimal separator.
 236  *     <tr style="vertical-align:top">
 237  *          <td><code>'</code>
 238  *          <td>Prefix or suffix
 239  *          <td>No
 240  *          <td>Used to quote special characters in a prefix or suffix,
 241  *              for example, <code>"'#'#"</code> formats 123 to
 242  *              <code>"#123"</code>.  To create a single quote
 243  *              itself, use two in a row: <code>"# o''clock"</code>.

 244  * </table>
 245  * </blockquote>
 246  *
 247  * <h4>Scientific Notation</h4>
 248  *
 249  * <p>Numbers in scientific notation are expressed as the product of a mantissa
 250  * and a power of ten, for example, 1234 can be expressed as 1.234 x 10^3.  The
 251  * mantissa is often in the range 1.0 &le; x {@literal <} 10.0, but it need not
 252  * be.
 253  * <code>DecimalFormat</code> can be instructed to format and parse scientific
 254  * notation <em>only via a pattern</em>; there is currently no factory method
 255  * that creates a scientific notation format.  In a pattern, the exponent
 256  * character immediately followed by one or more digit characters indicates
 257  * scientific notation.  Example: <code>"0.###E0"</code> formats the number
 258  * 1234 as <code>"1.234E3"</code>.
 259  *
 260  * <ul>
 261  * <li>The number of digit characters after the exponent character gives the
 262  * minimum exponent digit count.  There is no maximum.  Negative exponents are
 263  * formatted using the localized minus sign, <em>not</em> the prefix and suffix




 155  * 1,0000,0000.  If you supply a pattern with multiple grouping characters, the
 156  * interval between the last one and the end of the integer is the one that is
 157  * used. So <code>"#,##,###,####"</code> == <code>"######,####"</code> ==
 158  * <code>"##,####,####"</code>.
 159  *
 160  * <h4>Special Pattern Characters</h4>
 161  *
 162  * <p>Many characters in a pattern are taken literally; they are matched during
 163  * parsing and output unchanged during formatting.  Special characters, on the
 164  * other hand, stand for other characters, strings, or classes of characters.
 165  * They must be quoted, unless noted otherwise, if they are to appear in the
 166  * prefix or suffix as literals.
 167  *
 168  * <p>The characters listed here are used in non-localized patterns.  Localized
 169  * patterns use the corresponding characters taken from this formatter's
 170  * <code>DecimalFormatSymbols</code> object instead, and these characters lose
 171  * their special status.  Two exceptions are the currency sign and quote, which
 172  * are not localized.
 173  *
 174  * <blockquote>
 175  * <table class="altrows">
 176  * <caption style="display:none">Chart showing symbol, location, localized, and meaning.</caption>
 177  * <thead>
 178  *     <tr>
 179  *          <th style="text-align:left">Symbol
 180  *          <th style="text-align:left">Location
 181  *          <th style="text-align:left">Localized?
 182  *          <th style="text-align:left">Meaning
 183  * </thead>
 184  * <tbody>
 185  *     <tr style="vertical-align:top">
 186  *          <td><code>0</code>
 187  *          <td>Number
 188  *          <td>Yes
 189  *          <td>Digit
 190  *     <tr style="vertical-align: top">
 191  *          <td><code>#</code>
 192  *          <td>Number
 193  *          <td>Yes
 194  *          <td>Digit, zero shows as absent
 195  *     <tr style="vertical-align:top">
 196  *          <td><code>.</code>
 197  *          <td>Number
 198  *          <td>Yes
 199  *          <td>Decimal separator or monetary decimal separator
 200  *     <tr style="vertical-align: top">
 201  *          <td><code>-</code>
 202  *          <td>Number
 203  *          <td>Yes
 204  *          <td>Minus sign
 205  *     <tr style="vertical-align:top">
 206  *          <td><code>,</code>
 207  *          <td>Number
 208  *          <td>Yes
 209  *          <td>Grouping separator
 210  *     <tr style="vertical-align: top">
 211  *          <td><code>E</code>
 212  *          <td>Number
 213  *          <td>Yes
 214  *          <td>Separates mantissa and exponent in scientific notation.
 215  *              <em>Need not be quoted in prefix or suffix.</em>
 216  *     <tr style="vertical-align:top">
 217  *          <td><code>;</code>
 218  *          <td>Subpattern boundary
 219  *          <td>Yes
 220  *          <td>Separates positive and negative subpatterns
 221  *     <tr style="vertical-align: top">
 222  *          <td><code>%</code>
 223  *          <td>Prefix or suffix
 224  *          <td>Yes
 225  *          <td>Multiply by 100 and show as percentage
 226  *     <tr style="vertical-align:top">
 227  *          <td><code>\u2030</code>
 228  *          <td>Prefix or suffix
 229  *          <td>Yes
 230  *          <td>Multiply by 1000 and show as per mille value
 231  *     <tr style="vertical-align: top">
 232  *          <td><code>¤</code> (<code>\u00A4</code>)
 233  *          <td>Prefix or suffix
 234  *          <td>No
 235  *          <td>Currency sign, replaced by currency symbol.  If
 236  *              doubled, replaced by international currency symbol.
 237  *              If present in a pattern, the monetary decimal separator
 238  *              is used instead of the decimal separator.
 239  *     <tr style="vertical-align:top">
 240  *          <td><code>'</code>
 241  *          <td>Prefix or suffix
 242  *          <td>No
 243  *          <td>Used to quote special characters in a prefix or suffix,
 244  *              for example, <code>"'#'#"</code> formats 123 to
 245  *              <code>"#123"</code>.  To create a single quote
 246  *              itself, use two in a row: <code>"# o''clock"</code>.
 247  * </tbody>
 248  * </table>
 249  * </blockquote>
 250  *
 251  * <h4>Scientific Notation</h4>
 252  *
 253  * <p>Numbers in scientific notation are expressed as the product of a mantissa
 254  * and a power of ten, for example, 1234 can be expressed as 1.234 x 10^3.  The
 255  * mantissa is often in the range 1.0 &le; x {@literal <} 10.0, but it need not
 256  * be.
 257  * <code>DecimalFormat</code> can be instructed to format and parse scientific
 258  * notation <em>only via a pattern</em>; there is currently no factory method
 259  * that creates a scientific notation format.  In a pattern, the exponent
 260  * character immediately followed by one or more digit characters indicates
 261  * scientific notation.  Example: <code>"0.###E0"</code> formats the number
 262  * 1234 as <code>"1.234E3"</code>.
 263  *
 264  * <ul>
 265  * <li>The number of digit characters after the exponent character gives the
 266  * minimum exponent digit count.  There is no maximum.  Negative exponents are
 267  * formatted using the localized minus sign, <em>not</em> the prefix and suffix


< prev index next >