Here you can find the source of convertToLong(String decimal, int precision)
public static long convertToLong(String decimal, int precision)
//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(); } }