Description Of BigDecimal: longValue()
The java.math.BigDecimal.longValue() converts this BigDecimal to a long . This conversion is analogous to the narrowing primitive conversion from double to short as defined in section 5.1.3 of The Java? Language Specification : any fractional part of this BigDecimal will be discarded, and if the resulting " BigInteger " is too big to fit in a long , only the low-order 64 bits are returned. Note that this conversion can lose information about the overall magnitude and precision of this BigDecimal value as well as return a result with the opposite sign.BigDecimal.longValue() method returns this BigDecimal converted to a long .
Code Example Java BigDecimal
import java.math.BigDecimal; public class BigDecimalExam { public static void main(String[] args) { BigDecimal bg1 = new BigDecimal("-75.00"); BigDecimal bg2 = new BigDecimal("25.50"); BigDecimal bg3 = new BigDecimal("25"); long b1 = bg1.longValue(); long b2 = bg2.longValue(); long b3 = bg3.longValue(); System.out.println(b1); System.out.println(b2); System.out.println(b3); } }
ไม่มีความคิดเห็น :
แสดงความคิดเห็น