MathUtil (xmlbeans API)

org.apache.xmlbeans.impl.util

## Class MathUtil

- java.lang.Object
- - org.apache.xmlbeans.impl.util.MathUtil

-     public class MathUtil
      extends Object

  Internal Use Only. Utility methods for dealing with conversions

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static BigDecimal` | `parseAsBigDecimal(String s)`
    `static BigDecimal` | `parseAsBigDecimal(String s, int maxNumberOfChars)`
    `static BigInteger` | `parseAsBigInteger(String s)`
    `static double` | `parseAsDouble(String s)`
    `static double` | `parseAsDouble(String s, int maxNumberOfChars)`
    `static float` | `parseAsFloat(String s)`
    `static float` | `parseAsFloat(String s, int maxNumberOfChars)`
    `static int` | `parseAsInt(String s)`
    `static long` | `parseAsLong(String s)`
    `static int` | `safeDoubleToInt(double d)`
    `static int` | `safeFloatToInt(float f)`
    `static BigInteger` | `toBigInteger(BigDecimal value)`
    `static int` | `toInt(BigDecimal value)`
    `static long` | `toLong(BigDecimal value)`

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

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

- - ### Method Detail

    - #### safeFloatToInt

          public static int safeFloatToInt(float f)

    - #### safeDoubleToInt

          public static int safeDoubleToInt(double d)

    - #### parseAsBigDecimal

          public static BigDecimal parseAsBigDecimal(String s)

      Parameters:
        `s` - string to parse
      Returns:
        valid BigDecimal
      Throws:
        `NumberFormatException` - if parse fails
        `IllegalArgumentException` - if string is too long
        `NullPointerException` - if string is null

    - #### parseAsBigDecimal

          public static BigDecimal parseAsBigDecimal(String s,
                                                     int maxNumberOfChars)

      Parameters:
        `s` - string to parse
        `maxNumberOfChars` - maximum number of characters allowed in the string
      Returns:
        valid BigDecimal
      Throws:
        `NumberFormatException` - if parse fails
        `IllegalArgumentException` - if string is too long
        `NullPointerException` - if string is null

    - #### parseAsBigInteger

          public static BigInteger parseAsBigInteger(String s)

      Parameters:
        `s` - string to parse
      Returns:
        valid BigInteger
      Throws:
        `NumberFormatException` - if parse fails
        `IllegalArgumentException` - if string is too long
        `NullPointerException` - if string is null

    - #### parseAsFloat

          public static float parseAsFloat(String s)

      Parameters:
        `s` - string to parse
      Returns:
        valid Float
      Throws:
        `NumberFormatException` - if parse fails
        `IllegalArgumentException` - if string is too long
        `NullPointerException` - if string is null

    - #### parseAsFloat

          public static float parseAsFloat(String s,
                                           int maxNumberOfChars)

      Parameters:
        `s` - string to parse
        `maxNumberOfChars` - maximum number of characters allowed in the string
      Returns:
        valid float
      Throws:
        `NumberFormatException` - if parse fails
        `IllegalArgumentException` - if string is too long
        `NullPointerException` - if string is null

    - #### parseAsDouble

          public static double parseAsDouble(String s)

      Parameters:
        `s` - string to parse
      Returns:
        valid float
      Throws:
        `NumberFormatException` - if parse fails
        `IllegalArgumentException` - if string is too long
        `NullPointerException` - if string is null

    - #### parseAsDouble

          public static double parseAsDouble(String s,
                                             int maxNumberOfChars)

      Parameters:
        `s` - string to parse
        `maxNumberOfChars` - maximum number of characters allowed in the string
      Returns:
        valid float
      Throws:
        `NumberFormatException` - if parse fails
        `IllegalArgumentException` - if string is too long
        `NullPointerException` - if string is null

    - #### parseAsLong

          public static long parseAsLong(String s)

      Parameters:
        `s` - string to parse
      Returns:
        valid long
      Throws:
        `NumberFormatException` - if parse fails
        `IllegalArgumentException` - if string is too long
        `NullPointerException` - if string is null

    - #### parseAsInt

          public static int parseAsInt(String s)

      Parameters:
        `s` - string to parse
      Returns:
        valid int
      Throws:
        `NumberFormatException` - if parse fails
        `IllegalArgumentException` - if string is too long
        `NullPointerException` - if string is null

    - #### toBigInteger

          public static BigInteger toBigInteger(BigDecimal value)

      Parameters:
        `value` - BigDecimal to convert
      Returns:
        valid BigInteger
      Throws:
        `IllegalArgumentException` - if the input has an absolute exponent that is too large to safely convert
        `NullPointerException` - if value is null

    - #### toLong

          public static long toLong(BigDecimal value)

      Parameters:
        `value` - BigDecimal to convert
      Returns:
        valid long
      Throws:
        `IllegalArgumentException` - if the input has an absolute exponent that is too large to safely convert or if the value is out of long range
        `NullPointerException` - if value is null

    - #### toInt

          public static int toInt(BigDecimal value)

      Parameters:
        `value` - BigDecimal to convert
      Returns:
        valid int
      Throws:
        `IllegalArgumentException` - if the input has an absolute exponent that is too large to safely convert or if the value is out of int range
        `NullPointerException` - if value is null