Class Numbers


  • public final class Numbers
    extends Object
    A set of functions to work with numbers
    • Method Detail

      • toString

        public static String toString​(Number number)
        Default toString method for numbers. Default format is "#.###". See toString(Number, String) for details.
        Parameters:
        number - any instance of Number
        Returns:
        string representation of a given number.
      • toString

        public static String toString​(Number number,
                                      String pattern)
        Formatting method for numbers. Uses pattern parameter for defining output format. Format symbols:
        Symbol Location Symbol Meaning 
        0NumberDigit
        #NumberDigit, zero shows as absent
        .Number.Decimal separator or monetary decimal separator
        -Number-Minus sign
        ,Number,Grouping separator
        ENumberESeparates mantissa and exponent in scientific notation. Need not be quoted in prefix or suffix.
        ;Subpattern boundarySeparates positive and negative subpatterns
        %Prefix or suffix%Multiply by 100 and show as percentage
        ‰Prefix or suffix‰Multiply by 1000 and show as per mille value
        'Prefix or suffixUsed to quote special characters in a prefix or suffix, for example, "'#'#" formats 123 to "#123". To create a single quote itself, use two in a row: "# o''clock".

        Some examples:

        12,000 1.2E4  003 neg 003 3% 30‰ #3% 
        Pattern Number Result Comment 
        0000 42 0042 
        0000.000 42.42 0042.420 
        0000.000 42 0042.000 
        #.## 3000.452 3000.45  
        #.## 3000.4 3000.4  
        #.## 3000 3000  
        #,###.# 12000  
        #0E0 12000  
        003   
        000;neg 0 3  
        000;neg 0 -3 For negative numbers positive pattern enhanced by negative pattern is used 
        0% 0.03  
        0‰ 0.03  
        '#'0'%' 3  
        Parameters:
        number - any instance of Number
        pattern - target pattern
        Returns:
        string representation of a given number.