Java Number Convert convertToLong(String decimal, int precision)

Here you can find the source of convertToLong(String decimal, int precision)

Description

convert To Long

License

Open Source License

Declaration

public static long convertToLong(String decimal, int precision) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import com.google.common.base.Strings;
import java.math.BigDecimal;

public class Main {

    public static long convertToLong(String decimal, int precision) {
        if (Strings.isNullOrEmpty(decimal)) {
            return 0L;
        }/*from w  ww .ja  va  2 s .  c  om*/
        long time = 1L;
        for (int i = 0; i < precision; i++) {
            time = time * 10L;
        }
        BigDecimal bigDecimal = new BigDecimal(decimal);
        if (time != 1L) {
            bigDecimal = bigDecimal.multiply(new BigDecimal(time));
        }
        return bigDecimal.longValueExact();
    }
}

Related

  1. convertToDecimal(Number n)
  2. convertToHours(long workingDuration)
  3. convertToInchesOfMercury(double altimeterSetting, String unit)
  4. convertToJBPM(Object value)
  5. convertToKg(int value)
  6. ConvertToMeters(double distance)
  7. convertToMm(double value)
  8. convertToMoney(float money)
  9. getMoneyConversion(int money, int divisor)