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()方法与示例相关推荐

  1. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  2. java中intvalue方法作用_Java Integer类intValue()方法及示例

    整数类intValue()方法intValue()方法在java.lang包中可用. intValue()方法用于返回此Integer对象表示的值,该值转换为int类型(通过强制转换). intVal ...

  3. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  4. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  5. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  6. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  7. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  8. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

  9. java arraylist.add(),Java ArrayList add()方法与示例

    ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...

最新文章

  1. Linux下查看和添加环境变量
  2. 成功解决ValueError: not enough values to unpack (expected 2, got 1)
  3. AndroidStudio中使用XML和Java代码混合控制UI界面实现QQ相册照片列表页面
  4. SAP CRM HANA report模型的数据库存储表
  5. 近似线性依靠matlab_不要仅仅依靠单元测试
  6. mybatis.net - 5 嵌入资源与引用资源
  7. 考研英语核心词汇辨析(黑魔方系列2007版之十一)
  8. model数据库orm操作
  9. 码匠编程:零基础从前端入门到前端开发工程师路线
  10. python unittest断言_python接口自动化(二十四)--unittest断言——中(详解)
  11. 32岁了 学python 来的及吗-32岁的程序员去了国企工作, 晒出年薪, 网友: 我没看错吧...
  12. java提前多久显示,Java当前日期/时间比原始时间提前1小时显示
  13. 代码精进之代码规范(二)
  14. RS-485半双工延时问题
  15. html使用css居中
  16. con和com开头单词规律_con和com的前缀区别。背单词时总是搞不清什么时候是con什么时候是com之后找到了不同之处,c...
  17. 关闭mongodb数据库 (netstat -lanp | grep “27017“)
  18. vscode安装mindmap插件之后无法打开.km文件,vscode中文版mindmap安装
  19. 并查集 --算法竞赛专题解析(3)
  20. 异构网络互联;路由与转发;SDN基本概念;拥塞控制

热门文章

  1. java接口方法实现_Java接口的简单定义与实现方法示例
  2. esxi挂载Linux的nfs盘,ESXi安装centos7挂载群晖NFS
  3. php mysql 图像_php-向/从MySQL数据库插入/查看图像
  4. oracle数据库连接名是什么,连接到Oracle数据库的几种命名方式
  5. mf模型 svd++_序列推荐模型(一): FPMC
  6. 创造型模式——单例模式
  7. Kewail-邮件短信接口的基础教程
  8. AI工程师职业规划和学习路线完整版
  9. 来自我的破船大大的博客,记录他的iOS成长之路,与君同勉!
  10. 2017 Google 开发者大会直播入口