Here you can find the source of secondsBigDecimalFromDuration(long s, int n)
public static BigDecimal secondsBigDecimalFromDuration(long s, int n)
//package com.java2s; //License from project: Open Source License import java.math.BigDecimal; import java.math.BigInteger; public class Main { public static BigDecimal secondsBigDecimalFromDuration(long s, int n) { if (n == 0) return BigDecimal.valueOf(s); int scale = 9; // A simple way to make sure s * 1000000000L doesn't overflow: boolean huge = (int) s != s; long ns = huge ? n : s * 1000000000L + n; while (ns % 10 == 0) { ns = ns / 10;//from w w w . java2 s. c o m scale--; } BigDecimal dec = new BigDecimal(BigInteger.valueOf(ns), scale); if (huge) dec = BigDecimal.valueOf(s).add(dec); return dec; } }