Convert double and long to BigDecimal

ReturnMethodSummary
static BigDecimalvalueOf(double val)Translates a double into a BigDecimal.
static BigDecimalvalueOf(long val)Translates a long value into a BigDecimal with a scale of zero.
static BigDecimalvalueOf(long unscaledVal, int scale)Translates a long unscaled value and an int scale into a BigDecimal.

import java.math.BigDecimal;
 

public class Main {
 
    public static void main(String[] args) {
        System.out.println(BigDecimal.valueOf(1.00001));
    }
}

The output:


1.00001
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.