Class NumberFormatter


  • public class NumberFormatter
    extends java.lang.Object
    class to format integers, longs, doubles etc.
    • Constructor Summary

      Constructors 
      Constructor Description
      NumberFormatter()
      set up the defaults
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String formatDouble​(double d)
      returns a formatted double.
      java.lang.String formatDouble​(double d, int precision)
      returns a formatted double.
      java.lang.String formatInt​(int i, int length)
      returns a formatted integer with length digits
      void setZapp0​(boolean zapp0)
      if set, remove trailing 0
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NumberFormatter

        public NumberFormatter()
        set up the defaults
    • Method Detail

      • setZapp0

        public void setZapp0​(boolean zapp0)
        if set, remove trailing 0
        Parameters:
        zapp0 -
      • formatInt

        public java.lang.String formatInt​(int i,
                                          int length)
        returns a formatted integer with length digits
        Parameters:
        i - the integer to format
        length - total length of including leading zeros
        Returns:
        the formatted string that represents the integer
      • formatDouble

        public java.lang.String formatDouble​(double d,
                                             int precision)
        returns a formatted double. Truncates to at most precision digits after the "."
        If precision=0, the . is stripped
        Parameters:
        d - the double to format
        precision - maximum precision, depending on value of zapp0, trailing 0s are discarded or kept
        Returns:
        the formatted string that represents d TBD handle exp format, null if NaN
      • formatDouble

        public java.lang.String formatDouble​(double d)
        returns a formatted double. Truncates to 8 digits after the "."
        If the double is representable as an integer, any ".0" is stripped.
        Parameters:
        d - the double to format
        Returns:
        the formatted string that represents d TBD handle exp format