使用java.math.BigDecimal
2005-05-27 15:47
573 查看
public class BigDecimal extends Number 不可变的、任意精度的带符号的十进制数。 一个 BigDecimal 由一个任意精度的整数值和一个非负的整数标度组成,整数标度代表小数点右边的十进制数字的个数(用 BigDecimal 表示的数值大小是 intVal/10**scale)。 BigDecimals 提供基本的算术操作、精度处理、比较、格式转换和散列。
BigDecimal 类使它的用户对舍入行为有完全的控制权,迫使用户显式地指定能够舍弃部分精度( (除法 和 setScale))的舍入操作的舍入行为。为达到该目的,该类提供了八个 舍入模式 。同时针对 BigDecimal 的精度操作提供了两种类型的操作:数值调整/舍入 (scaling/rounding)操作和小数点移动操作。Scaling/Rounding 操作 (SetScale) 返回一个 BigDecimal,其数值近似 (或精确) 等于操作数,其有效范围是指定的值;也就是说,它们以对数值产生最小影响的方式增加或减少精度。十进制小数点移动操作 (movePointLeft 和 movePointRight)返回一个 BigDecimal ,它是把操作数的小数点在指定方向移动一个指定距离产生的;这种操作可以改变一个数字的值但不影响它的精度。
public class BigDecimalextends Numberimplements Comparable Immutable, arbitrary-precision signed decimal numbers. A BigDecimal consists of an arbitrary precision integer unscaled value and a non-negative 32-bit integer scale, which represents the number of digits to the right of the decimal point. The number represented by the BigDecimal is (unscaledValue/10scale). BigDecimal provides operations for basic arithmetic, scale manipulation, comparison, hashing, and format conversion. The BigDecimal class gives its user complete control over rounding behavior, forcing the user to explicitly specify a rounding behavior for operations capable of discarding precision (divide(BigDecimal, int), divide(BigDecimal, int, int), and setScale(int, int)). Eight rounding modes are provided for this purpose. Two types of operations are provided for manipulating the scale of a BigDecimal: scaling/rounding operations and decimal point motion operations. Scaling/rounding operations (setScale) return a BigDecimal whose value is approximately (or exactly) equal to that of the operand, but whose scale is the specified value; that is, they increase or decrease the precision of the number with minimal effect on its value. Decimal point motion operations (movePointLeft(int) and movePointRight(int)) return a BigDecimal created from the operand by moving the decimal point a specified distance in the specified direction; that is, they change a number's value without affecting its precision. For the sake of brevity and clarity, pseudo-code is used throughout the descriptions of BigDecimal methods. The pseudo-code expression (i + j) is shorthand for "a BigDecimal whose value is that of the BigDecimal i plus that of the BigDecimal j." The pseudo-code expression (i == j) is shorthand for "true if and only if the BigDecimal i represents the same value as the the BigDecimal j." Other pseudo-code expressions are interpreted similarly. Note: care should be exercised if BigDecimals are to be used as keys in a SortedMap or elements in a SortedSet, as BigDecimal's natural ordering is inconsistent with equals. See Comparable, SortedMap or SortedSet for more information.
BigDecimal 类使它的用户对舍入行为有完全的控制权,迫使用户显式地指定能够舍弃部分精度( (除法 和 setScale))的舍入操作的舍入行为。为达到该目的,该类提供了八个 舍入模式 。同时针对 BigDecimal 的精度操作提供了两种类型的操作:数值调整/舍入 (scaling/rounding)操作和小数点移动操作。Scaling/Rounding 操作 (SetScale) 返回一个 BigDecimal,其数值近似 (或精确) 等于操作数,其有效范围是指定的值;也就是说,它们以对数值产生最小影响的方式增加或减少精度。十进制小数点移动操作 (movePointLeft 和 movePointRight)返回一个 BigDecimal ,它是把操作数的小数点在指定方向移动一个指定距离产生的;这种操作可以改变一个数字的值但不影响它的精度。
public class BigDecimalextends Numberimplements Comparable Immutable, arbitrary-precision signed decimal numbers. A BigDecimal consists of an arbitrary precision integer unscaled value and a non-negative 32-bit integer scale, which represents the number of digits to the right of the decimal point. The number represented by the BigDecimal is (unscaledValue/10scale). BigDecimal provides operations for basic arithmetic, scale manipulation, comparison, hashing, and format conversion. The BigDecimal class gives its user complete control over rounding behavior, forcing the user to explicitly specify a rounding behavior for operations capable of discarding precision (divide(BigDecimal, int), divide(BigDecimal, int, int), and setScale(int, int)). Eight rounding modes are provided for this purpose. Two types of operations are provided for manipulating the scale of a BigDecimal: scaling/rounding operations and decimal point motion operations. Scaling/rounding operations (setScale) return a BigDecimal whose value is approximately (or exactly) equal to that of the operand, but whose scale is the specified value; that is, they increase or decrease the precision of the number with minimal effect on its value. Decimal point motion operations (movePointLeft(int) and movePointRight(int)) return a BigDecimal created from the operand by moving the decimal point a specified distance in the specified direction; that is, they change a number's value without affecting its precision. For the sake of brevity and clarity, pseudo-code is used throughout the descriptions of BigDecimal methods. The pseudo-code expression (i + j) is shorthand for "a BigDecimal whose value is that of the BigDecimal i plus that of the BigDecimal j." The pseudo-code expression (i == j) is shorthand for "true if and only if the BigDecimal i represents the same value as the the BigDecimal j." Other pseudo-code expressions are interpreted similarly. Note: care should be exercised if BigDecimals are to be used as keys in a SortedMap or elements in a SortedSet, as BigDecimal's natural ordering is inconsistent with equals. See Comparable, SortedMap or SortedSet for more information.
相关文章推荐
- JavaSE—java.math.BigDecimal中的setSCale函数的使用
- Java中的java.math.BigDecimal的使用
- Java中正则表达式和常用的Math、Random、System、BigInteger、BigDecimal、Date/DateFormat、Calendar类的使用
- java.math.BigDecimal的使用方法
- Java中正则表达式及其常用类Math、Calendar、Date、BigDecimal、BigInterger、System、Rondom的使用
- 使用java.math.BigDecimal
- java.math.BigDecimal的用法
- java 使用Random和Math.random()去生成10以内的随机数
- Java中BigDecimal的使用
- Java 使用BigDecimal实现精确计算
- java.Math.bigdecimal的用法简介(大数据处理)
- Android使用java的Math.Random获取随机色值
- Java 基础 分别使用Math和Random生成随机数
- java.math.BigDecimal、BinInteger类的用法
- java.math包中的BigInteger和BigDecimal
- 使用Java Math.random()利用蒙特卡洛方法计算pi值
- Android使用java的Math.Random获取随机色值
- java使用BigDecimal 处理商业精度及高精度详解
- Java Math.pow(x,y)的使用坑
- java.math.BigInteger使用心得总结