java.lang.ArithmeticException:Non-terminating decimal expansion; no exact representable decimal result.
Reference: https://stackoverflow.com/questions/4591206/arithmeticexception-non-terminating-decimal-expansion-no-exact-representable?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
From the Java 5 docs (Java 8 docs here):
When a MathContext object is supplied with a precision setting of 0 (for example, MathContext.UNLIMITED), arithmetic operations are exact, as are the arithmetic methods which take no MathContext object. (This is the only behavior that was supported in releases prior to 5.)
As a corollary of computing the exact result, the rounding mode setting of a MathContext object with a precision setting of 0 is not used and thus irrelevant. In the case of divide, the exact quotient could have an infinitely long decimal expansion; for example, 1 divided by 3.
If the quotient has a nonterminating decimal expansion and the operation is specified to return an exact result, an ArithmeticException is thrown. Otherwise, the exact result of the division is returned, as done for other operations.
To fix, you need to do something like this:
a.divide(b,2,RoundingMode.HALF_UP)
where 2 is precision and RoundingMode.HALF_UP is rounding mode
相关推荐
你是否因为JS端的小数计算的精度不足而发愁过呢 其实有个不错的资源可以利用。 引用附件的JS,就可以轻松搞定JS的计算问题了。...alert(new BigDecimal("10.00").divide(new BigDecimal("3E+10"))); } //--> </SCRIPT>
详细的描述BigDecimal的用法,使你能很快对BigDecimal有较深的认识
e = e.add(BigDecimal.prototype.ONE.divide(denominator, scale, BigDecimal.prototype.ROUND_HALF_UP)); denominator = denominator.multiply(new BigDecimal(iteration+'')); ++iteration; } equal(e....
a general method for solving divide and conquer recurrences
其中BigDecimal-all-last.min.js大小为:26KB GZIP压缩后7K,完全可以用于实际生产过程中。 简单例子: var a = new BigDecimal...a.divide(b)); 详细用法请参见压缩包内test目录中的:BigDecimal_test.html文件。
前言 对于某些数据精度的计算,无法确定数据精度,java对于这些数据也提供了...BigDecimal divide(BigDecimal divisor, int scale, int roundingMode);//除法 除不尽的时候会报错 BigDecimal.ROUND_HALF_UP;//除不尽的
这是用Verilog编写的除法模块(divide module),包括了divide程序设计模块和测试模块。
opencv 中关于 mat 矩阵的基本运算操作,有实例和注释,可以方便查看结果
JUnit测试代码,此文件为java工程文件,例子为整数除法。
The Divide-and-Conquer Strategy
根据该手册,可以配置LPm_divide.quartus自带的IP中除法器。可以配置为单时钟运行。或者多时钟运行。根据我的经验,要跑到到100M,需要20个时钟。
INT 00 - DIVIDE ERROR (internal interrupt) Automatically called at end of DIV or IDIV operation that results in error. Normally set by DOS to display an error message and abort the program.
FPGA Verilog浮点数除法运算,采用单精度浮点型小数格式,运算结果精度可设置,可封装成IP核
自己经常调用的FPGA分频程序
LCS匹配算法,divide and conquer LCS
一款可以实现一次性出一个商或者两个商的除法器
this is divide and conquer 2 takes note.
CARRY LOOK AHEAD USING VERILOG
//BigDecimal ⾼精度⼩数运算 BigDecimal b3=new BigDecimal("0.09"); BigDecimal b4=new BigDecimal("0.01"); //加法 System.out.println(b3.add(b4)); //减法 System.out.println(b3.subtract(b4)); //乘法 ...
flex divide_例子,快下吧。。。。。