Description Of BigDecimal: doubleValue()
The java.math.BigDecimal.doubleValue() converts this BigDecimal to a double . This conversion is similar to the narrowing primitive conversion from double to float as defined in section 5.1.3 of The Java? Language Specification : if this BigDecimal has too great a magnitude represent as a double , it will be converted to Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY as appropriate. Note that even when the return value is finite, this conversion can lose information about the precision of the BigDecimal value.BigDecimal.doubleValue() method returns this BigDecimal converted to a double
Code Example Java BigDecimal
import java.math.BigDecimal; public class BigDecimalExam { public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("1000.12"); BigDecimal bg2 = new BigDecimal("332.32"); double bg3 = bg1.doubleValue(); double bg4 = bg2.doubleValue(); System.out.println(bg3); System.out.println(bg4); } }
ไม่มีความคิดเห็น :
แสดงความคิดเห็น