使用BigDecimal的小数点后的最大位数 [英] Maximum number of digits after the decimal point using BigDecimal
问题描述
Java中 BigDecimal
值小数点后的最大位数是多少?
What is the maximum number of digits we can have after the decimal point of a BigDecimal
value in Java?
推荐答案
这几乎是无限的。如果将scale设置为整数的最大值,则可以在小数点后存储大约20亿个数字,但如果尝试执行此操作,可能会耗尽内存。如果您需要存储这么多的数字以确定限制是一个问题,那么您可能需要重新考虑程序的设计。
It's (almost) unlimited. You can store roughly 2 billion digits after the decimal point if scale is set to the maximum value of an integer, although you may run out of memory if you try to do this. If you need to store so many digits that the limit is a problem then you probably need to rethink the design of your program.
参见 BigDecimal文档:
不可变,任意精度的带符号十进制数。 BigDecimal由任意精度整数非标度值和32位整数标度组成。如果为零或正数,则比例是小数点右侧的位数。如果是负数,则将数字的未缩放值乘以10来表示比例的否定。因此,BigDecimal表示的数字的值是(unscaledValue×10 -scale )。
这篇关于使用BigDecimal的小数点后的最大位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!