NumberUtil (FreeMarker 2.3.35 API)
Description: declaration: package: freemarker.template.utility, class: NumberUtil

Package freemarker.template.utility

# Class NumberUtil

java.lang.Object
freemarker.template.utility.NumberUtil

public class NumberUtil extends Object
Number- and math-related utilities.

Since:
  2.3.20

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static int`
  `getSignum​(Number num)`
  `static boolean`
  `hasTypeThatIsKnownToNotSupportInfiniteAndNaN​(Number num)`
  Tells if the type of the parameter number is known to not be able to represent infinite (positive or negative) and NaN.
  `static boolean`
  `isInfinite​(Number num)`
  `static boolean`
  `isIntegerBigDecimal​(BigDecimal bd)`
  Tells if a `BigDecimal` stores a whole number.
  `static boolean`
  `isNaN​(Number num)`
  `static int`
  `toIntExact​(Number num)`
  Converts a `Number` to `int` whose mathematical value is exactly the same as of the original number.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### isInfinite

    public static boolean isInfinite​(Number num)

  - ### isNaN

    public static boolean isNaN​(Number num)

  - ### getSignum

    public static int getSignum​(Number num) throws ArithmeticException
    Returns:
      -1 for negative, 0 for zero, 1 for positive.
    Throws:
      `ArithmeticException` - if the number is NaN

  - ### isIntegerBigDecimal

    public static boolean isIntegerBigDecimal​(BigDecimal bd)
    Tells if a `BigDecimal` stores a whole number. For example, it returns `true` for `1.0000`, but `false` for `1.0001`.
    Since:
      2.3.21

  - ### hasTypeThatIsKnownToNotSupportInfiniteAndNaN

    public static boolean hasTypeThatIsKnownToNotSupportInfiniteAndNaN​(Number num)
    Tells if the type of the parameter number is known to not be able to represent infinite (positive or negative) and NaN. If this returns `false`, that doesn't mean that it can do that, because it's maybe just that this utility doesn't know that type.
    Since:
      2.3.28

  - ### toIntExact

    public static int toIntExact​(Number num)
    Converts a `Number` to `int` whose mathematical value is exactly the same as of the original number.
    Throws:
      `ArithmeticException` - if the conversion to `int` is not possible without losing precision or overflow/underflow.
    Since:
      2.3.22