概述
BigDecimal类的intValue()方法 (BigDecimal Class intValue() method)
intValue() method is available in java.math package.
intValue()方法在java.math包中可用。
intValue() method is used to convert a BigDecimal to an integer and when the converted BigDecimal value is large 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() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
intValue()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
intValue() method does not throw an exception at the time of converting BigDecimal to int.
在将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:
例:
// Java program to demonstrate the example
// of int intValue() method of BigDecimal
import java.math.*;
public class IntValueOfBD {
public static void main(String args[]) {
// Initialize two variables first is
// of "double" and second is of "String"
// type
double val = 115.23;
String str = "100";
// Initialize two BigDecimal objects
BigDecimal b_dec1 = new BigDecimal(val);
BigDecimal b_dec2 = new BigDecimal(str);
// convert this BigDecimal (b_dec1) into
// an int, variable named i_conv
int i_conv = b_dec1.intValue();
System.out.println("b_dec1.intValue(): " + i_conv);
// convert this BigDecimal (b_dec2) into
// an int, variable named i_conv
i_conv = b_dec2.intValue();
System.out.println("b_dec2.intValue(): " + i_conv);
}
}
Output
输出量
b_dec1.intValue(): 115
b_dec2.intValue(): 100
翻译自: https://www.includehelp.com/java/bigdecimal-intvalue-method-with-example.aspx
最后
以上就是矮小音响为你收集整理的Java BigDecimal intValue()方法与示例的全部内容,希望文章能够帮你解决Java BigDecimal intValue()方法与示例所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复