< prev index next >

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

Print this page




 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="striped">
 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




 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="striped">
 176  * <caption style="display:none">Chart showing symbol, location, localized, and meaning.</caption>
 177  * <thead>
 178  *     <tr>
 179  *          <th scope="col" style="text-align:left">Symbol
 180  *          <th scope="col" style="text-align:left">Location
 181  *          <th scope="col" style="text-align:left">Localized?
 182  *          <th scope="col" style="text-align:left">Meaning
 183  * </thead>
 184  * <tbody>
 185  *     <tr style="vertical-align:top">
 186  *          <th scope="row"><code>0</code>
 187  *          <td>Number
 188  *          <td>Yes
 189  *          <td>Digit
 190  *     <tr style="vertical-align: top">
 191  *          <th scope="row"><code>#</code>
 192  *          <td>Number
 193  *          <td>Yes
 194  *          <td>Digit, zero shows as absent
 195  *     <tr style="vertical-align:top">
 196  *          <th scope="row"><code>.</code>
 197  *          <td>Number
 198  *          <td>Yes
 199  *          <td>Decimal separator or monetary decimal separator
 200  *     <tr style="vertical-align: top">
 201  *          <th scope="row"><code>-</code>
 202  *          <td>Number
 203  *          <td>Yes
 204  *          <td>Minus sign
 205  *     <tr style="vertical-align:top">
 206  *          <th scope="row"><code>,</code>
 207  *          <td>Number
 208  *          <td>Yes
 209  *          <td>Grouping separator
 210  *     <tr style="vertical-align: top">
 211  *          <th scope="row"><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  *          <th scope="row"><code>;</code>
 218  *          <td>Subpattern boundary
 219  *          <td>Yes
 220  *          <td>Separates positive and negative subpatterns
 221  *     <tr style="vertical-align: top">
 222  *          <th scope="row"><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  *          <th scope="row"><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  *          <th scope="row"><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  *          <th scope="row"><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


< prev index next >