栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 软件开发 > 后端开发 > C/C++/C#

java.math.BigDecimal

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java.math.BigDecimal

java.math.BigDecimal 一、定义

不可变的、任意精度的有符号十进制数。表示的数字的值BigDecimal是(unscaledValue × 10^-scale )。
BigDecimal类使用户可以完全控制舍入行为。如果没有指定取整方式,无法表示准确的结果,则抛出异常;否则,可以通过MathContext操作提供适当的对象来执行所选精度和舍入模式的计算。(使用RoundingMode的枚举值控制舍入)
两种控制位数的方式:缩放/舍入操作(setScalend round);其值大约(或完全)等于操作数的值,但其比例或精度是指定值(也就是说,它们增加或减少存储数字的精度,而对其值的影响最小);小数点移动操作(movePointLeft和movePointRight):通过将小数点沿指定方向移动指定距离操作数

二、构造函数
ConstructorDescription
BigDecimal(BinInteger val)Translates a BigInteger into a BigDecimal
BigDecimal(BigInteger unscaledVal, int scale)Translates a BigInteger unscaled value and an int scale into a BigDecimal
BigDecimal(BigInteger unscaledVal, int scale, MathContext mc)TTranslates a BigInteger unscaled value and an int scale into a BigDecimal, with rounding according to the context settings
BigDecimal(BigInteger val, MathContext mc)Translates a BigInteger into a BigDecimal rounding according to the context settings
BigDecimal(char[] in)Translates a character array representation of a BigDecimal into a BigDecimal, accepting the same sequence of characters as the BigDecimal(String) constructor
BigDecimal(char[] in, int offset, int len)Translates a character array representation of a BigDecimal into a BigDecimal, accepting the same sequence of characters as the BigDecimal(String) constructor, while allowing a sub-array to be specified
BigDecimal(char[] in, int offset, int len, MathContext mc)Translates a character array representation of a BigDecimal into a BigDecimal, accepting the same sequence of characters as the BigDecimal(String) constructor, while allowing a sub-array to be specified and with rounding according to the context settings
BigDecimal(char[] in, MathContext mc)Translates a character array representation of a BigDecimal into a BigDecimal, accepting the same sequence of characters as the BigDecimal(String) constructor and with rounding according to the context settings
BigDecimal(double val)Translates a double into a BigDecimal which is the exact decimal representation of the double’s binary floating-point value
BigDecimal(double val, MathContext mc)Translates a double into a BigDecimal, with rounding according to the context settings
BigDecimal(int val)Translates an int into a BigDecimal
BigDecimal(int val, MathContext mc)Translates an int into a BigDecimal, with rounding according to the context settings
BigDecimal(long val)Translates a long into a BigDecimal
BigDecimal(long val, MathContext mc)Translates a long into a BigDecimal, with rounding according to the context settings
BigDecimal(String val)Translates the string representation of a BigDecimal into a BigDecimal
BigDecimal(String val, MathContext mc)Translates the string representation of a BigDecimal into a BigDecimal, accepting the same strings as the BigDecimal(String) constructor, with rounding according to the context settings
三、方法
MethodDescription
(BigDecimal)abs()Returns a BigDecimal whose value is the absolute value of this BigDecimal, and whose scale is this.scale()
(BigDecimal)add(BigDecimal augend)Returns a BigDecimal whose value is (this + augend), and whose scale is max(this.scale(), augend.scale())
(byte)byteValueExact()Converts this BigDecimal to a byte, checking for lost information
(int)compareTo(BigDecimal val)Compares this BigDecimal with the specified BigDecimal
(BigDecimal)divide(BigDecimal divisor)Returns a BigDecimal whose value is (this / divisor), and whose preferred scale is (this.scale() - divisor.scale()); if the exact quotient cannot be represented (because it has a non-terminating decimal expansion) an ArithmeticException is thrown
(BigDecimal)divide(BigDecimal divisor, int roundingMode)Returns a BigDecimal whose value is (this / divisor), and whose scale is this.scale()
(double)doubleValue()Converts this BigDecimal to a double
(boolean)equals(Object x)Compares this BigDecimal with the specified Object for equality
(float)floatValue()Converts this BigDecimal to a float
(int)hashCode()Returns the hash code for this BigDecimal
(int)intValue()Converts this BigDecimal to an int
(int)intValueExact()Converts this BigDecimal to an int, checking for lost information
(long)longValue()Converts this BigDecimal to a long
(long)longValueExact()Converts this BigDecimal to a long, checking for lost information
(BigDecimal)max(BigDecimal val)Returns the maximum of this BigDecimal and val
(BigDecimal)min(BigDecimal val)Returns the minimum of this BigDecimal and val
(BigDecimal)multiply(BigDecimal multiplicand)Returns a BigDecimal whose value is (this × multiplicand), and whose scale is (this.scale() + multiplicand.scale())
(BigDecimal)multiply(BigDecimal multiplicand, MathContext mc)Returns a BigDecimal whose value is (this × multiplicand), with rounding according to the context settings
(BigDecimal)negate()Returns a BigDecimal whose value is (-this), and whose scale is this.scale()
(BigDecimal)negate(MathContext mc)Returns a BigDecimal whose value is (-this), with rounding according to the context settings
(BigDecimal)plus()Returns a BigDecimal whose value is (+this), and whose scale is this.scale()
(BigDecimal)plus(MathContext mc)Returns a BigDecimal whose value is (+this), with rounding according to the context settings
(BigDecimal)pow(int n)Returns a BigDecimal whose value is (this^n), The power is computed exactly, to unlimited precision
(BigDecimal)remainder(BigDecimal divisor)Returns a BigDecimal whose value is (this % divisor)
(BigDecimal)remainder(BigDecimal divisor, MathContext mc)Returns a BigDecimal whose value is (this % divisor), with rounding according to the context settings
(BigDecimal)subtract(BigDecimal subtrahend)Returns a BigDecimal whose value is (this - subtrahend), and whose scale is max(this.scale(), subtrahend.scale())
(BigDecimal)subtract(BigDecimal subtrahend, MathContext mc)Returns a BigDecimal whose value is (this - subtrahend), with rounding according to the context settings
(BigInteger)toBigInteger()Converts this BigDecimal to a BigInteger
(BigInteger)toBigIntegerExact()Converts this BigDecimal to a BigInteger, checking for lost information
(String)toString()Returns the string representation of this BigDecimal, using scientific notation if an exponent is needed
(BigDecimal)ulp()Returns the size of an ulp, a unit in the last place, of this BigDecimal

更多内容请参考链接:https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html

转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/1038746.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号