BigDecimal类的toBigIntegerExact()方法 (BigDecimal Class toBigIntegerExact() method)

  • toBigIntegerExact() method is available in java.math package.

    toBigIntegerExact()方法在java.math包中可用。

  • toBigIntegerExact() method is used to convert this BigDecimal into the exact BigInteger value and it will throw an exception when this BigDecimal holds some fractional part that is other than 0.

    toBigIntegerExact()方法用于将此BigDecimal转换为确切的BigInteger值,并且当此BigDecimal持有非0的小数部分时,它将引发异常。

  • toBigIntegerExact() 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.

    toBigIntegerExact()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • toBigIntegerExact() method may throw an exception at the time of converting this object into BigInteger.

    在将此对象转换为BigInteger时, toBigIntegerExact()方法可能会引发异常。

    ArithmeticException: This exception may throw when this BigDecimal object holds a decimal part that is other than 0.

    ArithmeticException :当此BigDecimal对象包含非0的小数部分时,可能引发此异常。

Syntax:

句法:

    public BigInteger toBigIntegerExact();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of this method is BigInteger, it returns the exact conversion of this BigDecimal object value to a BigInteger value.

此方法的返回类型为BigInteger ,它将此BigDecimal对象值精确转换为BigInteger值。

Example:

例:

// Java program to demonstrate the example
// of BigInteger toBigIntegerExact() method of BigDecimal
import java.math.*;
public class ToBigIntegerExactOfBD {public static void main(String args[]) {// Initialize two variables - double and
// String type
double val = 1234521.0;
String str = "1211124";
// Initialize two BigDecimal objects
BigDecimal b_dec1 = new BigDecimal(val);
BigDecimal b_dec2 = new BigDecimal(str);
/* In this method it throws an exception
when we pass any non-zero value after
decimal in this BigDecimal */
// converts this BigDecimal b_dec1 value into
// an exact BigInteger value, and store the result
// in a variable named b_int_conv
BigInteger b_int_conv = b_dec1.toBigIntegerExact();
System.out.println("b_dec1.toBigIntegerExact(): " + b_int_conv);
// converts this BigDecimal b_dec2 value into
// an exact BigInteger value, and store the result
// in a variable named b_int_conv
b_int_conv = b_dec2.toBigIntegerExact();
System.out.println("b_dec2.toBigIntegerExact(): " + b_int_conv);
}
}

Output

输出量

b_dec1.toBigIntegerExact(): 1234521
b_dec2.toBigIntegerExact(): 1211124

翻译自: https://www.includehelp.com/java/bigdecimal-tobigintegerexact-method-with-example.aspx

Java BigDecimal toBigIntegerExact()方法(带示例)相关推荐

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

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

  2. java getmonth_Java LocalDateTime类| 带示例的getMonth()方法

    java getmonth LocalDateTime类getMonth()方法 (LocalDateTime Class getMonth() method) getMonth() method i ...

  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. windows oracle path,Oracle-Windows平台Path的问题
  2. SAP HUM嵌套HU场景里是否可以直接对内层HU执行VLMOVE?
  3. 一款超级简单的瀑布流的制作
  4. 转:PHP开发框架流行度排名:Laravel居首
  5. Python列表中数据插入数据库
  6. 《指数型组织》学习总结
  7. abp框架java_asp.net core之abp框架
  8. LibreELEC(kodi)安装 IPTV
  9. cookie.setValue一些注意事项
  10. Hadoop集群搭建(超级详细)
  11. MATLAB输出白色背景图片
  12. python入门部分基础知识(下)
  13. Linux 系统日常运维九大技能和运维网络知识总结
  14. 腾讯云服务器性能评测:8核 16G 18M 配置
  15. OpenGL圆柱面绘制贴图
  16. bmp180气压传感器工作原理_40张动图看懂各种传感器工作原理
  17. RD client、远程桌面、smb等远程相关的使用与注意
  18. HTG评论GE Link入门套件:最经济的智能灯泡选择
  19. Compound学习(二) 简单部署
  20. 2005年11月网络工程师试题

热门文章

  1. java异常标记_java.lang.RuntimeException:错误:0D0680A8:asn1编码例程:ASN1_CHECK_TLEN:错误的标记...
  2. java 百度poi_Android应用中使用百度地图API之POI(三)
  3. 怎样用html制作动态心,利用html+css3制作心的跳动动画
  4. xbox手柄接收器驱动_xbox手柄连接 win10电脑
  5. 计算机专业知识是什么范围,计算机基础知识考题
  6. html5语义化标签 加粗,html5标签 H5标签
  7. mysql 5.5.18下载_MySQL5.7.18下载和安装过程图文详解
  8. mysql 尝试读取超过流末尾的_MySql异常:尝试读取超出流末尾的内容
  9. python字符串百分号_Python字符串格式化的2种方法
  10. mysqldump备份(全量+增量)