Java BigDecimal secondsBigDecimalFromDuration(long s, int n)

Here you can find the source of secondsBigDecimalFromDuration(long s, int n)

Description

seconds Big Decimal From Duration

License

Open Source License

Declaration

public static BigDecimal secondsBigDecimalFromDuration(long s, int n) 

Method Source Code

//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;
    }
}

Related

  1. safeToBigDecimal(Object obj1)
  2. scalarMult(BigDecimal scalar, Vector a)
  3. scale(BigDecimal b1, BigDecimal b2)
  4. scale2(BigDecimal valor)
  5. scaleCurrency(BigDecimal amount)
  6. signum(final BigDecimal value)
  7. sine(BigDecimal x)
  8. sortByValues( Map map)
  9. sortMapByBDValue(Map oriMap)