Java BigDecimal toBigIntegerExact()方法(帶示例)

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/542186.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542186.shtml
英文地址,請注明出處:http://en.pswp.cn/news/542186.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Linux中的軟件管理

1. 使用已有的網絡安裝資源安裝軟件 cd /etc/yum.repos.d/ (移動到yum源指向的文件配置目錄下) vim westos.repo (新建文件,yum下后綴必須為.repo) 編輯這個文件里面寫 [redhat] (軟件倉庫名稱) namefirefox &#x…

楚留香ai人臉識別_戴口罩居然也能人臉識別?這些AI黑科技真的藏不住了.........

當人工智能遇見影像技術,將會釋放出多少意想不到的巨大能量?「喔圖知圖實驗室」瞄準當下的影像痛點,持續發力升級AI黑科技,帶來兩大必殺技——人臉識別再度升級、AI智能旋轉校正。戴口罩也能識別——人臉識別升級戴口罩人臉識別如…

android--------Popupwindow的使用

2019獨角獸企業重金招聘Python工程師標準>>> PopupWindow在Android.widget包下,項目中經常會使用到PopupWindow做菜單選項, PopupWindow這個類用來實現一個彈出框,可以使用任意布局的View作為其內容,這個彈出框是懸浮…

使用JavaScript中的示例的escape()函數

While transferring the data over the network or sometimes while saving data to the database, we need to encode the data. The function escape() is a predefined function in JavaScript, which encodes the given string. 在通過網絡傳輸數據或有時將數據保存到數據庫…

安裝虛擬機的腳本

1. 先安裝生成自動安裝腳本的工具 yum install system-config-kickstart -y 2. 打開這個軟件 system-config-kickstart 基本設置:更改時區為上海,設置root用戶密碼 2)設置安裝方法為網絡安裝,將共享的鏡像文件地址正確填寫 3&…

小小小游戲

寫著玩 FlappyBird 視頻:https://pan.baidu.com/s/1sljIR5z 游戲:https://pan.baidu.com/s/1ge8j7Ej 項目:https://pan.baidu.com/s/1eSysxpw Breakout 視頻:https://pan.baidu.com/s/1gfhv4hd 項目:https://pan.baidu.com/s/1hs8xPly QBert 視頻:https://pan.baidu.com/s/1s…

go在方法中修改結構體的值_[Go]結構體及其方法

結構體類型可以包含若干字段,每個字段通常都需要有確切的名字和類型。也可以不包含任何字段,這樣并不是沒有意義的,因為還可以為這些類型關聯上一些方法,這里可以把方法看作事函數的特殊版本。函數事獨立的程序實體,可…

to_number用法示例_Number()函數以及JavaScript中的示例

to_number用法示例Number()函數 (Number() function) Number() function is a predefined global function in JavaScript, it used to convert an object to the number. If the function is not able to convert the object in a number – it returns "NaN". (Rea…

系統延時任務及定時任務

1. 系統延時任務&#xff1a; at相關命令 at time 設定任務執行時間at> rm -fr /mnt/* 任務動作at> <EOT> <<ctrld 執行任務at的命令&#xff1a; -l ##查看任務列表-c …

cpn tools查看運行時間_Jmeter在Linux下的運行測試

一、JMeterApache JMeter是Apache組織開發的基于Java的壓力測試工具。用于對軟件做壓力測試&#xff0c;它最初被設計用于Web應用測試&#xff0c;但后來擴展到其他測試領域。1.1、JMeter的作用能夠對HTTP和FTP服務器進行壓力和性能測試&#xff0c; 也可以對任何數據庫進行同樣…

css div滾動_如何使用CSS創建可垂直滾動的div?

css div滾動Introduction: 介紹&#xff1a; Dealing with divs has become a regularity and divs are used for many purposes like to structure our code and to segregate our various sections of codes. Besides, we are also aware of many properties that we can im…

Linux中磁盤分區的管理

1. 本地存儲設備的識別 fdisk -l真實存在的設備cat /proc/partitions系統識別的設備blkid系統可使用的設備df系統正在掛載的設備 真實存在的設備不一定可識別&#xff0c;識別到的的設備不一定可使用 2. 設備的掛載和卸載 1&#xff09;設備名稱 /dev/xdx …

python中時間的加減_python日期加減

python中關于時間和日期函數的常用計算總結 python中關于時間和日期函數有time和datatime 1.獲取當前時間的兩種方法: import datetime,time now = time.strftime("%Y-%m-%d %H:%M:%S") print now now = datetime.datetime.now()... 文章 技術小胖子 2017-11-08 848…

bst 刪除節點_在BST中刪除大于或等于k的節點

bst 刪除節點Problem statement: 問題陳述&#xff1a; Given a BST and a value x, write a function to delete the nodes having values greater than or equal to x. The function will return the modified root. 給定一個BST和一個值x &#xff0c;編寫一個函數刪除值大…

游戲架構之二(轉)

棋牌類游戲常用架構&#xff1a; 我從事過4年的棋牌類游戲開發&#xff0c;使用過的架構大致如上&#xff0c;各模塊解釋如下。 LoginServer&#xff1a; 登陸服務器&#xff0c;主要負責player 的登陸請求&#xff0c;驗證player的合法性&#xff0c;為合法的player分配sessio…

對lvm介紹

1. 什么是LVM LVM是 Logical Volume Manager&#xff08;邏輯卷管理&#xff09;的簡寫&#xff0c;它是Linux環境下對磁盤分區進行管理的一種機制&#xff0c;用戶在無需停機的情況下可以方便地調整各個分區大小。 lvm中的一些常見符號及意義 pv物理卷被lv命令處理過的物理分…

pythonweb自動化測試實例_[轉載]python?webdriver自動化測試實例

python webdriver自動化測試初步印象以下示例演示啟動firefox&#xff0c;瀏覽google.com,搜索Cheese&#xff0c;等待搜索結果&#xff0c;然后打印出搜索結果頁的標題from selenium import webdriverfrom selenium.common.exceptions import TimeoutExceptionfrom selenium.w…

repeated_Ruby中帶有示例的Array.repeated_combination()方法

repeatedArray.repeated_combination()方法 (Array.repeated_combination() Method) In this article, we will study about Array.repeated_combination() method. You all must be thinking the method must be doing something which is related to creating combinations o…

ApacheHttpServer修改httpd.conf配置文件

轉自&#xff1a;https://blog.csdn.net/dream1120757048/article/details/77427351 1. 安裝完 Apache HTTP Server 之后&#xff0c;還需要修改一下配置文件。 Apache 的配置文件路徑如下&#xff1a; C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf…

大學物理實驗電學基本參數的測量實驗報告_大學物理電學實驗報告

技校網專門為您推薦的類似問題答案問題1&#xff1a;怎樣寫大學計算機基礎有關制作個人簡歷的實驗報告一、實驗名稱&#xff1a;個人簡歷的制作 二、實驗目的與要求: 1、熟悉Word 2003的基本操作 2、掌握利用網絡搜索獲得個人簡歷所需的資料 3、培養同學們動手能力和自學能力。…