Convert number to primitive wrapper like Boolean or Float

@param num
Number to conver
@param wrapper
Primitive wrapper type
@return Converted object
765622
public static Object convertNumberToWrapper(Number num, Class<?> wrapper) {
        //XXX Paul: Using valueOf will reduce object creation
        if (wrapper.equals(String.class)) {
            return num.toString();
        } else if (wrapper.equals(Boolean.class)) {
            return Boolean.valueOf(num.intValue() == 1);
        } else if (wrapper.equals(Double.class)) {
            return Double.valueOf(num.doubleValue());
        } else if (wrapper.equals(Long.class)) {
            return Long.valueOf(num.longValue());
        } else if (wrapper.equals(Float.class)) {
            return Float.valueOf(num.floatValue());
        } else if (wrapper.equals(Integer.class)) {
            return Integer.valueOf(num.intValue());
        } else if (wrapper.equals(Short.class)) {
            return Short.valueOf(num.shortValue());
        } else if (wrapper.equals(Byte.class)) {
            return Byte.valueOf(num.byteValue());
        }
        throw new ConversionException(String.format("Unable to convert number to: %s", wrapper));
    }
389644
public ValueNumber forNumber(int number) {
        if (number >= getNumValuesAllocated()) {
            throw new IllegalArgumentException("Value " + number + " has not been allocated");
        }
        return allocatedValueList.get(number);
    }
242477
@SuppressWarnings("unchecked")
	public static <T> T parseNumber(String value, Class<T> targetClass){
		if(value == null){
			return null;
		}
		try{
			if(Integer.class == targetClass){
				return (T)Integer.valueOf(value);
			}
			else if(Float.class == targetClass){
				return (T)Float.valueOf(value);
			}
			else if(Double.class == targetClass){
				return (T)Double.valueOf(value);
			}
			else if(Byte.class == targetClass){
				return (T)Byte.valueOf(value);
			}
			else if(Short.class == targetClass){
				return (T)Short.valueOf(value);
			}
			else if(Long.class == targetClass){
				return (T)Long.valueOf(value);
			}
			else{
				return null;
			}
		}
		catch(NumberFormatException e){}
		return null;
	}
475899
@Override
    public NumberType getNumberType() throws IOException {
        Object n = currentNode();
        if (n instanceof Integer) {
            return NumberType.INT;
        } else if (n instanceof BigInteger) {
            return NumberType.BIG_INTEGER;
        } else if (n instanceof BigDecimal) {
            return NumberType.BIG_DECIMAL;
        } else if (n instanceof Double) {
            return NumberType.DOUBLE;
        } else if (n instanceof Float) {
            return NumberType.FLOAT;
        } else if (n instanceof Long) {
            return NumberType.LONG;
        } else {
            throw _constructError(n + " is not a number");
        }
    }
482595
public static Object convertValue(final Object value, final Class<?> convertType) {
        if (null == value) {
            return convertNullValue(convertType);
        } 
        if (value.getClass() == convertType) {
            return value;
        }
        if (value instanceof Number) {
            return convertNumberValue(value, convertType);
        }
        if (value instanceof Date) {
            return convertDateValue(value, convertType);
        }
        if (String.class.equals(convertType)) {
            return value.toString();
        } else {
            return value;
        }
    }
322805
@Override
    public <T extends Number> T numberValue(Class<T> numberType) {
        return ConvertNumberValue.of(numberType, number);
    }
73413
static Number coerceToPrimitiveNumber(String pValue,
                                          Class pClass)
            throws ELException {
        if (pClass == Byte.class || pClass == Byte.TYPE) {
            return Byte.valueOf(pValue);
        } else if (pClass == Short.class || pClass == Short.TYPE) {
            return Short.valueOf(pValue);
        } else if (pClass == Integer.class || pClass == Integer.TYPE) {
            return Integer.valueOf(pValue);
        } else if (pClass == Long.class || pClass == Long.TYPE) {
            return Long.valueOf(pValue);
        } else if (pClass == Float.class || pClass == Float.TYPE) {
            return Float.valueOf(pValue);
        } else if (pClass == Double.class || pClass == Double.TYPE) {
            return Double.valueOf(pValue);
        } else {
            return PrimitiveObjects.getInteger(0);
        }
    }
167998
def _number_parser(str_to_number_func):
    """"""
    def _parse_number_value(element_text, state):
        value = None

        try:
            value = str_to_number_func(element_text)
        except (ValueError, TypeError):
            state.raise_error(InvalidPrimitiveValue,
                              'Invalid numeric value "{}"'.format(element_text))

        return value

    return _parse_number_value
762275
Number numberFor(Number source, Class<?> destinationType) {
    if (destinationType.equals(source.getClass()))
      return source;

    if (destinationType.equals(Byte.class)) {
      long longValue = source.longValue();
      if (longValue > Byte.MAX_VALUE)
        throw new Errors().errorTooLarge(source, destinationType).toMappingException();
      if (longValue < Byte.MIN_VALUE)
        throw new Errors().errorTooSmall(source, destinationType).toMappingException();
      return Byte.valueOf(source.byteValue());
    }

    if (destinationType.equals(Short.class)) {
      long longValue = source.longValue();
      if (longValue > Short.MAX_VALUE)
        throw new Errors().errorTooLarge(source, destinationType).toMappingException();
      if (longValue < Short.MIN_VALUE)
        throw new Errors().errorTooSmall(source, destinationType).toMappingException();
      return Short.valueOf(source.shortValue());
    }

    if (destinationType.equals(Integer.class)) {
      long longValue = source.longValue();
      if (longValue > Integer.MAX_VALUE)
        throw new Errors().errorTooLarge(source, destinationType).toMappingException();
      if (longValue < Integer.MIN_VALUE)
        throw new Errors().errorTooSmall(source, destinationType).toMappingException();
      return Integer.valueOf(source.intValue());
    }

    if (destinationType.equals(Long.class))
      return Long.valueOf(source.longValue());

    if (destinationType.equals(Float.class)) {
      if (source.doubleValue() > Float.MAX_VALUE)
        throw new Errors().errorTooLarge(source, destinationType).toMappingException();
      return Float.valueOf(source.floatValue());
    }

    if (destinationType.equals(Double.class))
      return Double.valueOf(source.doubleValue());

    if (destinationType.equals(BigDecimal.class)) {
      if (source instanceof Float || source instanceof Double)
        return new BigDecimal(source.toString());
      else if (source instanceof BigInteger)
        return new BigDecimal((BigInteger) source);
      else
        return BigDecimal.valueOf(source.longValue());
    }

    if (destinationType.equals(BigInteger.class)) {
      if (source instanceof BigDecimal)
        return ((BigDecimal) source).toBigInteger();
      else
        return BigInteger.valueOf(source.longValue());
    }

    throw new Errors().errorMapping(source, destinationType).toMappingException();
  }
164139
public static Object convertExample(String value, String type) {
        if (value == null) {
            return null;
        }

        try {
            switch (type) {
                case "integer":
                    return Integer.valueOf(value);
                case "number":
                    return Float.valueOf(value);
                case "boolean":
                    return Boolean.valueOf(value);
                case "string":
                    return value;
                default:
                    return value;
            }
        } catch (NumberFormatException e) {
            throw new RuntimeException(String.format("Value '%s' cannot be converted to '%s'", value, type), e);
        }
    }
1277366
public static float coerceToFloat(Object value, float defaultValue) {
    if (value instanceof Float) {
      return (float) value;
    }
    if (value instanceof Number) {
      return ((Number) value).floatValue();
    } else if (value instanceof String) {
      try {
        return Float.valueOf((String) value);
      } catch (NumberFormatException ignored) {
      }
    }
    return defaultValue;
  }
138610
static NumberMath getMath(Number number) {
        if (isLong(number)) {
            return LongMath.INSTANCE;
        }
        if (isFloatingPoint(number)) {
            return FloatingPointMath.INSTANCE;
        }
        if (isBigDecimal(number)) {
            return BigDecimalMath.INSTANCE;
        }
        if (isBigInteger(number)) {
            return BigIntegerMath.INSTANCE;
        }
        if (isInteger(number) || isShort(number) || isByte(number)) {
            return IntegerMath.INSTANCE;
        }
        // also for custom Number implementations
        return BigDecimalMath.INSTANCE;
    }
683117
static Number promoteToInteger(Object wrapper )
    {
        if ( wrapper instanceof Character )
            return Integer.valueOf(((Character) wrapper).charValue());
        if ( wrapper instanceof Byte || wrapper instanceof Short )
            return Integer.valueOf(((Number) wrapper).intValue());

        return (Number) wrapper;
    }
495399
public static Class<?> unboxType( Class<?> wrapperType )
    {
        Class<?> c = wrapperMap.get( wrapperType );
        if ( c != null )
            return c;
        throw new InterpreterError(
            "Not a primitive wrapper type: "+wrapperType );
    }
1023650
private Object convert(Object value, Class type) {

		Object convertedObject = null;

		if (type.equals(String.class)) {

			// strings can be returned immediately
			return value.toString();

		} else if (value instanceof Number) {

			Number number = (Number) value;

			if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
				return number.intValue();

			} else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
				return number.longValue();

			} else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
				return number.doubleValue();

			} else if (type.equals(Float.class) || type.equals(Float.TYPE)) {
				return number.floatValue();

			} else if (type.equals(Short.class) || type.equals(Integer.TYPE)) {
				return number.shortValue();

			} else if (type.equals(Byte.class) || type.equals(Byte.TYPE)) {
				return number.byteValue();

			}

		} else if (value instanceof List) {

			return value;

		} else if (value instanceof Map) {
			return value;
		}

		// fallback
		try {

			Method valueOf = type.getMethod("valueOf", String.class);
			if (valueOf != null) {

				convertedObject = valueOf.invoke(null, value.toString());

			} else {

				logger.warn("Unable to find static valueOf method for type {}", type);
			}

		} catch (Throwable t) {

			logger.warn("Unable to deserialize value {} of type {}, Class has no static valueOf method.", new Object[]{value, type});
		}

		return convertedObject;
	}
1320718
function(num) {
            if(typeof num !== "number") {
                return NaN;
            }
            var isNegative = (num < 0),
                result;

            if(isNegative) {
                num = -num;
            }
            if(num < 10) {
                num += (10 - num) / 10;
            }
            result = this.logBaseTen(num);
            return (isNegative) ? -result : result;
        }
155927
function commaNumber(inputNumber, optionalSeparator, optionalDecimalChar) {

  // we'll strip off and hold the decimal value to reattach later.
  // we'll hold both the `number` value and `stringNumber` value.
  let number, stringNumber, decimal

  // default `separator` is a comma
  const separator = optionalSeparator   || ','

  // default `decimalChar` is a period
  const decimalChar = optionalDecimalChar || '.'

  switch (typeof inputNumber) {

    case 'string':

      // if there aren't enough digits to need separators then return it
      // NOTE: some numbers which are too small will get passed this
      //       when they have decimal values which make them too long here.
      //       but, the number value check after this switch will catch it.
      if (inputNumber.length < (inputNumber[0] === '-' ? 5 : 4)) {
        return inputNumber
      }

      // remember it as a string in `stringNumber` and convert to a Number
      stringNumber = inputNumber

      // if they're not using the Node standard decimal char then replace it
      // before converting.
      number = decimalChar !== '.' ? Number(stringNumber.replace(decimalChar, '.'))
                                   : Number(stringNumber)
      break

    // convert to a string.
    // NOTE: don't check if the number is too small before converting
    //       because we'll need to return `stringNumber` anyway.
    case 'number':
      stringNumber = String(inputNumber)
      number       = inputNumber
      break

    // return invalid type as-is
    default: return inputNumber
  }

  // when it doesn't need a separator or isn't a number then return it
  if ((-1000 < number && number < 1000) || isNaN(number) || !isFinite(number)) {
    return stringNumber
  }

  // strip off decimal value to append to the final result at the bottom
  let decimalIndex = stringNumber.lastIndexOf(decimalChar)

  if (decimalIndex > -1) {
    decimal = stringNumber.slice(decimalIndex)
    stringNumber = stringNumber.slice(0, -decimal.length)
  }

  // else {
  //   decimal = null
  // }

  // finally, parse the string and add in separators
  stringNumber = parse(stringNumber, separator)

  // if there's a decimal value add it back on the end.
  // NOTE: we sliced() it off including the decimalChar, so it's good.
  return decimal ? stringNumber + decimal : stringNumber

}