Java Data Type Tutorial - Java BigDecimal.valueOf(long unscaledVal, int scale)








Syntax

BigDecimal.valueOf(long unscaledVal, int scale) has the following syntax.

public static BigDecimal valueOf(long unscaledVal,   int scale)

Example

In the following code shows how to use BigDecimal.valueOf(long unscaledVal, int scale) method.

//from   w ww .j  a v  a  2  s  .c om
import java.math.BigDecimal;

public class Main {

    public static void main(String[] args) {
        Long l = new Long("12345678");

        // assign the bigdecimal value of l to bg scale is 4
        BigDecimal bg = BigDecimal.valueOf(l, 4);

        System.out.println( bg );
    }
}

The code above generates the following result.