Java BigDecimal longValueExact()方法與示例

BigDecimal類longValueExact()方法 (BigDecimal Class longValueExact() method)

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

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

  • longValueExact() method is used to convert this BigDecimal to an exact long value. When this BigDecimal holds a fractional part other than 0 or not in a range to represent long then ArithmeticException is thrown.

    longValueExact()方法用于將此BigDecimal轉換為確切的long值。 當此BigDecimal的小數部分不為0或不在表示long的范圍內時,則拋出ArithmeticException。

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

    longValueExact()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • longValueExact() method may throw an exception at the time of converting BigDecimal to the long.

    在將BigDecimal轉換為long時, longValueExact()方法可能會引發異常。

    ArithmeticException: This exception may throw when this BigDecimal holds a fractional part that is other than 0 or the resulting value is not enough to adjust in a long.

    ArithmeticException :當此BigDecimal包含一個非0的小數部分或所得到的值不足以長時間調整時,可能會引發此異常。

Syntax:

句法:

    public long longValueExact();

Parameter(s):

參數:

  • It does not accept any parameter.

    它不接受任何參數。

Return value:

返回值:

The return type of this method is long, it gets the long representation of this BigDecimal.

此方法的返回類型為long ,它獲取此BigDecimal的long表示形式。

Example:

例:

// Java program to demonstrate the example 
// of long longValueExact() method of BigDecimal
import java.math.*;
public class LongValueExactOfBD {
public static void main(String args[]) {
// Initialize two variables first is
// of "float" and second is of "String"
// type
float val = 11562387.23f;
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
// a exact long, variable named l_conv
long l_conv = b_dec1.longValueExact();
System.out.println("b_dec1.longValueExact(): " + l_conv);
// convert this BigDecimal (b_dec2) into
// a exact long, variable named l_conv
l_conv = b_dec2.longValueExact();
System.out.println("b_dec2.longValueExact(): " + l_conv);
}
}

Output

輸出量

b_dec1.longValueExact(): 11562387
b_dec2.longValueExact(): 100

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

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

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

相關文章

c#中的多線程同步

在處理多線程同步問題的時候,我們一般有臨界區,互斥量,信號量和消息機制等幾種解決方案,在c#中可以非常方便的使用它們來實現進程的同步。下面我就常用的lock,Monitor和Mutex幾種來說明如何實現進程的同步。 lock和Monitor依靠一種…

ffplay SDL_OpenAudio (2 channels, 44100 Hz): WASAPI can‘t initialize audio client“

windows下: ffplay 提示"SDL_OpenAudio (2 channels, 44100 Hz): WASAPI can’t initialize audio client" 添加環境變量:SDL_AUDIODRIVERdirectsound

js 正則表達式,正整數

var ss "3.333";var type /^[0-9]*[1-9][0-9]*$/;var re new RegExp(type);alert(ss.match(re));if (ss.match(re) null) {alert("請輸入大于零的整數!");return;} 轉載于:https://www.cnblogs.com/lingxzg/archive/2012/08/02/2620543.html

java 根據類名示例化類_Java即時類| EpochSecond()方法的示例

java 根據類名示例化類EpochSecond()方法的即時類 (Instant Class ofEpochSecond() method) Syntax: 句法: public static Instant ofEpochSecond(long sec_val);public static Instant ofEpochSecond(long sec_val, long nanos_adjust);ofEpochSecond() method is…

java中Date()類型輸入數據的處理

對于Date類型的數據,需要輸入生日存入相應數據庫中 private Date birthday;// 生日package com.pdsu.mybatis.pojo;import java.io.Serializable; import java.util.Date;public class User implements Serializable {/*** */private static final long serialVers…

(擴展)歐幾里德快速冪

GCD模板 __int64 gcd(__int64 a,__int64 b) {return b0? a:gcd(b,a%b); } 歐幾里德算法又稱輾轉相除法,用于計算兩個整數a,b的最大公約數。其計算原理依賴于下面的定理: gcd函數就是用來求(a,b)的最大公約數的。 gcd函數的基本性質: gcd(a,…

匯編語言-002(.data、Equal、$、EQU 、MOV 、MOVSX、MOVZX)

1:變量相加程序 .386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.data firstval DWORD 20002000h secondval DWORD 11111111h thirdval DWORD 22222222h sum DWORD 0.code main PROCmov eax,firstvaladd eax,secondvaladd eax,thirdvalm…

\r與\n的區別,\r\n與\n或\r的區別(C語言/C#)

本文出處http://topic.csdn.net/t/20020718/07/882679.html 原作者:triout(笨牛) \r表示回車,\n表示換行,我們按回車按鈕的時候,系統自動產生回車和換行兩個字符: 回車僅僅是表示完成,把光…

通過ID查詢一個用戶的兩種開發方法

通過ID查詢一個用戶的兩種開發方法 數據庫建表sql語句如下:https://github.com/beyondyanyu/Sayingyy/blob/master/JDBC2-數據庫sql建表語句 ①,原始Dao開發: UserDao.java(接口): package com.pdsu.mybatis.dao;i…

duration java_Java Duration類| minusMinutes()方法與示例

duration java持續時間類minusMinutes()方法 (Duration Class minusMinutes() method) minusMinutes() method is available in java.time package. minusMinutes()方法在java.time包中可用。 minusMinutes() method is used to subtract the given duration in minutes from t…

Silverlight + WCF異步調用 例子

看大家好像對我的NParsing框架不是很感興趣(寫NParsing帖沒人頂我),那就給大家來點“甜品”,換換口謂。來說說Silverlight方面的東西。 在Silverlight中數據通信只能用異步。有人會覺得寫起來很麻煩,其實不然。也有很簡…

我博客主頁的搜索功能怎么不好用

用博客里面的搜索功能,“找找看”,搜索我博客里面的關鍵字,但是不能出現結果。但是我在別人的主頁上能夠搜索該人的內容,能夠查詢到記錄,難道博客園對每個博客的信息要先排序?目前我的還不在他的搜索數據庫…

小議SqlMapConfig.xml配置文件

①、mybatis-3-config.dtd 主要用于mybatis的核心配文件sqlMapConfig.xml的約束 sqlMapConfig.xml代碼如下&#xff1a; <?xml version"1.0" encoding"UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN&q…

ffmepg 命令提取音視頻數據

原文件&#xff1a; 1&#xff1a; 原音頻數據提取&#xff08;保留還是mp4的封裝格式的&#xff09;&#xff1a; ffmpeg -i test_1920x1080.mp4 -acodec copy -vn audio.mp4 -vn 就是沒有視頻&#xff0c; -acodec copy 音頻拷貝不進行任何轉碼 原視頻數據提取&#xff0…

Java BigInteger類| modInverse()方法與示例

BigInteger類modInverse()方法 (BigInteger Class modInverse() method) modInverse() method is available in java.math package. modInverse()方法在java.math包中可用。 modInverse() method is used to calculate the mod inverse by using the inverse of (this BigInteg…

【7】jQuery學習——入門jQuery選擇器之過濾選擇器-可見性過濾選擇器

這篇什么都不說&#xff0c;看標題就知道了&#xff0c;很簡單&#xff0c;就2個選擇器&#xff0c;嘿嘿 選擇器描述返回$("Element:hidden")選取所有不可見的元素集合元素$("Element:visible")選取所有可見元素集合元素這篇很簡單吧&#xff0c;就2個&…

Creating an undraggable TitleWindow container in Flex (轉載)

The following examples show how you can create an undraggable TitleWindow container by setting the isPopUp property to false on the TitleWindow instance. <?xml version"1.0" encoding"utf-8"?><!-- http://blog.flexexamples.com/2…

匯編語言-003(LAHF_SAHF 、XCHG、FLAGS、 OFFSET、ALIGN、PTR、LENGTHOF、SIZEOF)

1&#xff1a;LAHF將EFLAGS符號寄存器低8位字節復制到AH&#xff0c;SAHF將AH復制到EFLAGS符號寄存器低8位字節 .386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.data saveflags BYTE ?.code main PROClahfmov saveflags ,ahmov ah,saveflagssahfIN…

Mybatis中的核心配置文件SqlMapConfig.xml詳細介紹

一、properties&#xff08;屬性&#xff09; 可以引用java屬性文件中的配置信息如下 jdbc.properties代碼如下&#xff1a; jdbc.drivercom.mysql.jdbc.Driver jdbc.urljdbc:mysql://localhost:3306/mybatis?characterEncodingutf-8 jdbc.usernameroot jdbc.passwordbeyond…

用Kotlin開發您的第一個應用程序| Android與Kotlin

In the previous article, we learned how to setup Kotlin in the android studio? Now moving to journey ahead we are going to develop our first app with Kotlin. It is the basic app, but it will let you know the structure of the program. 在上一篇文章中&#x…