## org.eclipse.ocl.internal.evaluation
Class NumberUtil

    java.lang.Object
      org.eclipse.ocl.internal.evaluation.NumberUtil

    public class NumberUtil

extends Object

Utility for converting numeric values to double or integer precision as needed.

Since:
  1.2

Constructor Summary
`NumberUtil()`

Method Summary
`static Number` `coerceNumber(Number number)` Tests whether a given number can be safely coerced to `Double` or `Integer` without changing the value of the number.
`static Number` `higherPrecisionNumber(Number number)` Coerces the given number to `Double` or `Long` precision, if possible.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### NumberUtil

    public NumberUtil()

Method Detail

### coerceNumber

    public static Number coerceNumber(Number number)

  Tests whether a given number can be safely coerced to `Double` or `Integer` without changing the value of the number. Safe means that coercing a number to `Double` or `Integer` and then coercing it back to the original type will result in the same value (no loss of precision). This is trivial for types, which have a smaller domain then `Integer` or `Double`, but for example a `Long` number may not be safely coerced to `Integer`.

  If the coercion is safe, the number will be returned as either `Double` or `Integer`, as appropriate to the original precision. Otherwise the original number is returned.

  Parameters:
    `number` - a number to coerce to `Integer` or `Double`
  Returns:
    the coerced number, or the original number, if coercion was not safe

### higherPrecisionNumber

    public static Number higherPrecisionNumber(Number number)

  Coerces the given number to `Double` or `Long` precision, if possible. Note that this is only impossible for `BigDecimal` or `BigInteger` values, respectively, that are out of range of their primitive counterparts.

  Parameters:
    `number` - a number to coerce to `Long` or `Double`
  Returns:
    the coerced number, or the original number, in case of overflow

Copyright 2002, 2007 IBM Corporation and others. All Rights Reserved.