Class DecimalUtils


  • public class DecimalUtils
    extends java.lang.Object
    Static methods for dealing with floating point numbers in string decimal form.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String trimInsignificantZeros​(java.lang.String floatingPointNumber)
      Removes trailing zeros after the decimal dot and also the dot itself if there are no non-zero digits after it.
      static java.lang.String trimInsignificantZeros​(java.lang.String floatingPointNumber, char decimalSeparator, java.lang.String exponentialSeparator)
      Removes trailing zeros after the decimal separator and also the decimal separator itself if there are no non-zero digits after it.
      static java.lang.String trimInsignificantZeros​(java.lang.String floatingPointNumber, java.text.DecimalFormatSymbols symbols)
      Removes trailing zeros after the decimal separator and also the decimal separator itself if there are no non-zero digits after it.
      • Methods inherited from class java.lang.Object

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

      • trimInsignificantZeros

        @NonNull
        public static java.lang.String trimInsignificantZeros​(@NonNull
                                                              java.lang.String floatingPointNumber)
        Removes trailing zeros after the decimal dot and also the dot itself if there are no non-zero digits after it. Use trimInsignificantZeros(String, DecimalFormatSymbols) instead of this method if locale specific behavior is desired.
        Parameters:
        floatingPointNumber - the string representing a floating point number
        Returns:
        the original number with trailing zeros removed
      • trimInsignificantZeros

        public static java.lang.String trimInsignificantZeros​(@NonNull
                                                              java.lang.String floatingPointNumber,
                                                              @NonNull
                                                              java.text.DecimalFormatSymbols symbols)
        Removes trailing zeros after the decimal separator and also the decimal separator itself if there are no non-zero digits after it.
        Parameters:
        floatingPointNumber - the string representing a floating point number
        symbols - the decimal format symbols
        Returns:
        the original number with trailing zeros removed
      • trimInsignificantZeros

        public static java.lang.String trimInsignificantZeros​(@NonNull
                                                              java.lang.String floatingPointNumber,
                                                              char decimalSeparator,
                                                              java.lang.String exponentialSeparator)
        Removes trailing zeros after the decimal separator and also the decimal separator itself if there are no non-zero digits after it.
        Parameters:
        floatingPointNumber - the string representing a floating point number
        decimalSeparator - the decimal separator
        exponentialSeparator - the string used to separate the mantissa from the exponent
        Returns:
        the original number with trailing zeros removed