Java Utililty Methods Number Convert

List of utility methods to do Number Convert

Description

The list of methods to do Number Convert are organized into topic(s).

Method

BigDecimalconvertToDecimal(Number n)
convert To Decimal
if (n instanceof BigDecimal)
    return (BigDecimal) n;
else
    return new BigDecimal(n.toString());
doubleconvertToHours(long workingDuration)
convert To Hours
return BigDecimal.valueOf(workingDuration / (60.0 * 60.0 * 1000.0)).setScale(2, RoundingMode.HALF_UP)
        .doubleValue();
DoubleconvertToInchesOfMercury(double altimeterSetting, String unit)
convert To Inches Of Mercury
if ("hPa".equalsIgnoreCase(unit) || "http://opengis.net/def/uom/UCUM/0/hPa".equalsIgnoreCase(unit)) {
    double convertedVal = 0.0295299830714 * altimeterSetting;
    return round(convertedVal, 2);
return null;
ObjectconvertToJBPM(Object value)
A helper to convert result variables for jBPM.
if (BigDecimal.class.isInstance(value)) {
    BigDecimal v = (BigDecimal) value;
    if (v.scale() == 0) {
        return v.intValue();
    return v.doubleValue();
return value;
...
doubleconvertToKg(int value)
convert To Kg
return BigDecimal.valueOf(value).divide(BigDecimal.valueOf(1000)).setScale(3).doubleValue();
longconvertToLong(String decimal, int precision)
convert To Long
if (Strings.isNullOrEmpty(decimal)) {
    return 0L;
long time = 1L;
for (int i = 0; i < precision; i++) {
    time = time * 10L;
BigDecimal bigDecimal = new BigDecimal(decimal);
...
doubleConvertToMeters(double distance)
Convert To Meters
return Round((distance * 0.2), 2);
intconvertToMm(double value)
convert To Mm
return BigDecimal.valueOf(value).multiply(BigDecimal.TEN).intValue();
StringconvertToMoney(float money)
convert To Money
BigDecimal objB = new BigDecimal(Double.toString(money));
return objB.divide(BigDecimal.ONE, 2, BigDecimal.ROUND_HALF_UP).toString();
BigDecimalgetMoneyConversion(int money, int divisor)
get Money Conversion
BigDecimal a = new BigDecimal(money);
BigDecimal b = new BigDecimal(divisor);
return a.divide(b);