< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 156  *      last character of the integer and the decimal. Add
 157  *      (desiredSpaceCount - getEndIndex) spaces at the front of the string.
 158  *
 159  * <li> If you are using proportional fonts,
 160  *      instead of padding with spaces, measure the width
 161  *      of the string in pixels from the start to <code>getEndIndex</code>.
 162  *      Then move the pen by
 163  *      (desiredPixelWidth - widthToAlignmentPoint) before drawing the text.
 164  *      It also works where there is no decimal, but possibly additional
 165  *      characters at the end, e.g., with parentheses in negative
 166  *      numbers: "(12)" for -12.
 167  * </ol>
 168  *
 169  * <h3><a name="synchronization">Synchronization</a></h3>
 170  *
 171  * <p>
 172  * Number formats are generally not synchronized.
 173  * It is recommended to create separate format instances for each thread.
 174  * If multiple threads access a format concurrently, it must be synchronized
 175  * externally.







 176  *
 177  * @see          DecimalFormat
 178  * @see          ChoiceFormat
 179  * @author       Mark Davis
 180  * @author       Helena Shih
 181  */
 182 public abstract class NumberFormat extends Format  {
 183 
 184     /**
 185      * Field constant used to construct a FieldPosition object. Signifies that
 186      * the position of the integer part of a formatted number should be returned.
 187      * @see java.text.FieldPosition
 188      */
 189     public static final int INTEGER_FIELD = 0;
 190 
 191     /**
 192      * Field constant used to construct a FieldPosition object. Signifies that
 193      * the position of the fraction part of a formatted number should be returned.
 194      * @see java.text.FieldPosition
 195      */


   1 /*
   2  * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 156  *      last character of the integer and the decimal. Add
 157  *      (desiredSpaceCount - getEndIndex) spaces at the front of the string.
 158  *
 159  * <li> If you are using proportional fonts,
 160  *      instead of padding with spaces, measure the width
 161  *      of the string in pixels from the start to <code>getEndIndex</code>.
 162  *      Then move the pen by
 163  *      (desiredPixelWidth - widthToAlignmentPoint) before drawing the text.
 164  *      It also works where there is no decimal, but possibly additional
 165  *      characters at the end, e.g., with parentheses in negative
 166  *      numbers: "(12)" for -12.
 167  * </ol>
 168  *
 169  * <h3><a name="synchronization">Synchronization</a></h3>
 170  *
 171  * <p>
 172  * Number formats are generally not synchronized.
 173  * It is recommended to create separate format instances for each thread.
 174  * If multiple threads access a format concurrently, it must be synchronized
 175  * externally.
 176  *
 177  * @implSpec The {@link #format(double, StringBuffer, FieldPosition)},
 178  * {@link #format(long, StringBuffer, FieldPosition)} and
 179  * {@link #parse(String, ParsePosition)} methods may throw
 180  * {@code NullPointerException}, if any of their parameter is {@code null}.
 181  * The subclass may provide its own implementation and specification about
 182  * {@code NullPointerException}.
 183  *
 184  * @see          DecimalFormat
 185  * @see          ChoiceFormat
 186  * @author       Mark Davis
 187  * @author       Helena Shih
 188  */
 189 public abstract class NumberFormat extends Format  {
 190 
 191     /**
 192      * Field constant used to construct a FieldPosition object. Signifies that
 193      * the position of the integer part of a formatted number should be returned.
 194      * @see java.text.FieldPosition
 195      */
 196     public static final int INTEGER_FIELD = 0;
 197 
 198     /**
 199      * Field constant used to construct a FieldPosition object. Signifies that
 200      * the position of the fraction part of a formatted number should be returned.
 201      * @see java.text.FieldPosition
 202      */


< prev index next >