Java examples for java.math:BigDecimal Convert
double to Big Decimal
//package com.java2s; import java.math.BigDecimal; public class Main { public static void main(String[] argv) throws Exception { double val = 2.45678; System.out.println(toBigDecimal(val)); }/*from ww w . jav a2s . co m*/ public static BigDecimal toBigDecimal(double val) { assert !Double.isNaN(val); assert !Double.isInfinite(val); return new BigDecimal(Double.toString(val)); } public static BigDecimal toBigDecimal(long val) { return new BigDecimal(val); } }