`
一笑_奈何
  • 浏览: 66905 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

decimal的divide方法

    博客分类:
  • J2SE
阅读更多
金额的数据类型是BigDecimal
通过BigDecimal的divide方法进行除法时当不整除,出现无限循环小数时,就会抛异常的,异常如下:java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result. at java.math.BigDecimal.divide(Unknown Source)

应用场景:一批中供客户的单价是1000元/年,如果按月计算的话1000/12=83.3333333333....

解决之道:就是给divide设置精确的小数点divide(xxxxx,2, BigDecimal.ROUND_HALF_EVEN)
分享到:
评论

相关推荐

    JS的高精度计算(BigDecimal)

    你是否因为JS端的小数计算的精度不足而发愁过呢 其实有个不错的资源可以利用。 引用附件的JS,就可以轻松搞定JS的计算问题了。...alert(new BigDecimal("10.00").divide(new BigDecimal("3E+10"))); } //--> </SCRIPT>

    mc8051_overview.pdf

    - Optional implementation of the divide command (DIV) using a parallel divider - Optional implementation of the decimal adjustment command (DA) - No multiplexed I/O ports - 256 bytes internal RAM - Up...

    8086产品手册.rar

    Byte, Word, and Block Operations Y 8 and 16-Bit Signed and Unsigned Arithmetic in Binary or Decimal Including Multiply and Divide Y Range of Clock Rates: 5 MHz for 8086, 8 MHz for ...

    8051助记符/地址对照表

    DA - Decimal Adjust DEC - Decrement Register DIV - Divide Accumulator by B DJNZ - Decrement Register and Jump if Not Zero INC - Increment Register JB - Jump if Bit Set JBC - Jump if Bit Set and Clear ...

    precise-number:使用JavaScript精确执行加,减,乘和除算法

    使用JavaScript精确执行加,减,乘和除算法 为什么? 用纯JavaScript 1.1*1.1 === 1.2100000000000002是真的! 安装 npm install precise-number --...N.parse(number_string, decimal) //string to number with decim

    jquery 输入框数字限制插件

    直接看代码: 代码如下: (function($){ var keyCode={ BACKSPACE: 8, CAPS_LOCK: 20, COMMA: 188, ... 107, // NUMPAD_DECIMAL: 110, // NUMPAD_DIVIDE: 111, // NUMPAD_ENTER: 108, // NUMPAD_MULTIPLY: 106, // N

    Reasy-ui:路由器网库

    RIGHT: 93,CONTROL: 17,DELETE: 46,DOWN: 40,END: 35,ENTER: 13,ESCAPE: 27,HOME: 36,INSERT: 45,LEFT: 37,MENU: 93, // COMMAND_RIGHTNUMPAD_ADD: 107,NUMPAD_DECIMAL: 110,NUMPAD_DIVIDE: 111,NUMPAD_ENTER: 108,...

    分数的加减乘除运算Rational Numbers

    (Consider providing formatting capabilities that enable the user of the class to specify the number of digits of precision to the right of the decimal point.) – 提示: – 有理数是有分子、分母以形式a...

    Rational Numbers

    d. Divide two Rational numbers: The result of the division should be stored in reduced form. e. Print Rational numbers in the form a/b, where a is the numerator and b is the denominator. f. Print ...

    calculadoraJS:Free Code Camp课程的javascript中的计算器项目

    3:我的计算器应包含4个可单击的元素,每个元素都包含4个主要数学运算符之一,并具有以下对应的ID:id =“ add”,id =“ subtract”,id =“ multiply”,id =“ divide”。 4:我的计算器应包含一个可点击的元素...

    freecodecamp-calculator

    用户故事3:我的计算器应包含4个可点击的元素,每个元素都包含4个主要数学运算符之一,并具有以下对应的ID:id =“ add”,id =“ subtract”,id =“ multiply”,id =“ divide” 。 用户故事4:我的计算器应...

    HGE_系列教材(1-9)

    和释放来提高效率的方法) <5> GUI:强大而灵活的GUI 管理,支持动画式的GUI <6> 矢量(Vectors),对于2D 矢量的完全支持 3)Authoring Tools 层 <1> 资源的打包(pack):HGE 使用ZIP 格式的资源包,你可以使用...

    Microsoft Library MSDN4DOS.zip

    Chapter 6 Using Floating-Point and Binary Coded Decimal Numbers Chapter 7 Controlling Program Flow Chapter 8 Sharing Data and Procedures among Modules and Libraries Chapter 9 Using Macros Chapter 10 ...

    cpp-算法精粹

    Fraction to Recurring Decimal Factorial Trailing Zeroes Nim Game 模拟 Reverse Integer Palindrome Number Insert Interval Merge Intervals Minimum Window Substring Multiply Strings Substring with ...

    LeetCode最全代码

    ...The number of questions is increasing recently. Here is the classification of all `468` questions. ...I'll keep updating for full summary and better solutions....|-----|---------------- | --------------- |...

    Advanced-Division:用循环小数除以两个数字

    高级部门用循环小数除以两个数字包含代码: [removed][removed] 语法: advdiv(n1, n2, r, rstr1, rstr2) n1 –第一个数字n2 –第二个数字r –第一个数字的重复小数rstr1 –递归开始的字符串rstr2 –递归端的字符串...

    mfc可视化计算器编程

    case VK_DECIMAL: OnPt();break; case VK_DELETE: OnBackspace();break; case VK_RETURN: OnEqu();break; } CDialog::OnKeyDown(nChar, nRepCnt, nFlags); } BOOL CCalcDlg::PreTranslateMessage(MSG* ...

    jquery需要的所有js文件

    36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,...

    The Art of Assembly Language Programming

    Chapter One Chapter One - Data Representation 1.0 - Chapter Overview 1.1 - Numbering Systems 1.1.1 - A Review of the Decimal System 1.1.2 - The Binary Numbering System 1.1.3 - ...

Global site tag (gtag.js) - Google Analytics