Class NumberConverter


  • public final class NumberConverter
    extends java.lang.Object
    Utility class for numeric conversions
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isNumber​(java.lang.String source)
      Checks if string is a number
      static java.lang.Number narrow​(java.lang.Number number)
      Converts Number to the strictest numeric type available in following order: Integer, Long, Double, BigDecimal
      static <R> R narrow​(java.math.BigDecimal bigDecimal)
      Converts BigDecimal to the strictest numeric type available in following order: Integer, Long, Double, BigDecimal
      static java.lang.Double toDouble​(java.lang.Object value)
      Converts object to double
      static java.lang.Long toLong​(java.lang.Object value)
      Converts object to long
      • Methods inherited from class java.lang.Object

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

      • toLong

        public static java.lang.Long toLong​(java.lang.Object value)
        Converts object to long
        Parameters:
        value - Object to convert
        Returns:
        Long instance
      • toDouble

        public static java.lang.Double toDouble​(java.lang.Object value)
        Converts object to double
        Parameters:
        value - Object to convert
        Returns:
        Double instance
      • narrow

        public static <R> R narrow​(java.math.BigDecimal bigDecimal)
        Converts BigDecimal to the strictest numeric type available in following order: Integer, Long, Double, BigDecimal
        Type Parameters:
        R - Return parameter value
        Parameters:
        bigDecimal - BigDecimal instance
        Returns:
        Converted value
      • narrow

        public static java.lang.Number narrow​(java.lang.Number number)
        Converts Number to the strictest numeric type available in following order: Integer, Long, Double, BigDecimal
        Parameters:
        number - Number instance
        Returns:
        Converted value
      • isNumber

        public static boolean isNumber​(java.lang.String source)
        Checks if string is a number
        Parameters:
        source - String to check
        Returns:
        True or false