JavaBigDecimalintValue()⽅法与⽰例
BigDecimal类的intValue()⽅法 (BigDecimal Class intValue() method)
intValue() method is available in java.math package.
intValue() method
intValue()⽅法在java.math包中可⽤。
intValue()⽅法
intValue() method is used to convert a BigDecimal to an integer and when the converted BigDecimal value is large intValue() method
enough to fit into an integer then in that case low order 32 bits are to be retrieved and the returned value is with opposite sign.
intValue()⽅法⽤于将BigDecimal转换为整数,并且当转换的BigDecimal值⾜够⼤以适合整数时,在这种情况下,将检索低阶32 intValue()⽅法
位,并且返回的值带有相反的符号。
intValue() method is a non-static method, it is accessible with the class object only and if we try to access the method intValue() method
with the class name then we will get an error.
intValue()⽅法是⼀个⾮静态⽅法,只能通过类对象访问,如果尝试使⽤类名称访问该⽅法,则会收到错误消息。
intValue()⽅法
intValue() method does not throw an exception at the time of converting BigDecimal to int.
intValue() method
intValue()⽅法不会引发异常。
在将BigDecimal转换为int时, intValue()⽅法
Syntax:
句法:
public int intValue();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of this method is int, it gets the integer representation of this BigDecimal.
此⽅法的返回类型为int ,它获取此BigDecimal的整数表⽰形式。
Example:
例:
1// Java program to demonstrate the example
2// of int intValue() method of BigDecimal
3
4import java.math.*;
5
6public class IntValueOfBD {
7    public static void main(String args[]) {
8        // Initialize two variables first is
9        // of "double" and second is of "String"
10        // type
11        double val = 115.23;
12        String str = "100";
13
14        // Initialize two BigDecimal objects
15        BigDecimal b_dec1 = new BigDecimal(val);
16        BigDecimal b_dec2 = new BigDecimal(str);
17
18        // convert this BigDecimal (b_dec1) into
19        // an int, variable named i_conv
20        int i_conv = b_dec1.intValue();
21        System.out.println("b_dec1.intValue(): " + i_conv); 22
23        // convert this BigDecimal (b_dec2) into
java valueof24        // an int, variable named i_conv
25        i_conv = b_dec2.intValue();
26        System.out.println("b_dec2.intValue(): " + i_conv);
27    }
28}
Output
输出量
1b_dec1.intValue(): 115
2b_dec2.intValue(): 100

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。