常见的策略来处理货币密集软舍入误差? [英] Common strategies to deal with rounding errors in currency-intensive soft?

查看:197
本文介绍了常见的策略来处理货币密集软舍入误差?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是你的建议:

  1. 赔偿在对金钱的对象的集合大容量的数学运算积累误差。这是如何实现在生产code语言环境?
  2. 理论后面四舍五入会计。
  3. 任何文学的话题。
  1. compensation of accumulated error in bulk math operations on collections of Money objects. How is this implemented in your production code for your locale?
  2. theory behind rounding in accountancy.
  3. any literature on topic.

我目前正在读福勒。他提到钱的类型,它的typcal结构(的int,long,BigDecimal)的,但没有对战略的说。

I currently read Fowler. He mentions Money type, it's typcal structure (int, long, BigDecimal), but says nothing on strategies.

这钱倒圆(旧文章>和<一href="http://stackoverflow.com/questions/2511188/decimal-rounding-strategies-in-enterprise-applications">here)不提供细节和形式,我需要。

Older posts on money-rounding (here, and here) do not provide a details and formality I need.

的思考,我发现在INET涉及到圆的一半,甚至以平衡错误的最好方法。

Thoughts I found in the inet relate to "Round half even" as the best way to balance error.

感谢您的帮助。

推荐答案

有记录的财务数据时,有许多的四舍五入问题。 第一个问题是存储和检索精确的十进制数能力

There are many rounding issues when recording financial data. First issue is ability to store and retrieve exact decimal numbers

  • 在大多数数据库提供可以在其上前后小数点指定的位数小数的数据类型(货币变化的小数位数也一样,我已经经历了货币与0,2,3位小数)
  • 当这个数据处理,并要避免在应用程序端的任何意外的舍入误差可以使用的 BCD 作为通用的方法,也可以使用整数重新present任何固定的十进制符号或调配自己的
  • most databases offer decimal data type on which you can specify the number of digits before and after decimal point (currencies vary in number of decimal digits, too, I've dealt with currencies with 0, 2, 3 decimal digits)
  • when dealing with this data and you want to avoid any unexpected rounding errors on the application side you can use BCD as generic approach, or you can use integers to represent any fixed decimal notation or mix your own

如果这第一个问题整理出来,然后不添加(或减法)可以引入任何舍入误差。通过整数也是一样的乘法。

If this first issue is sorted out then no addition (or substraction) can introduce any rounding errors. Same goes for multiplication by integer.

第二个问题,你可以存储和检索而不会丢失信息数据之后,预计由于师(或乘以非整数)的舍入误差。

The second issue, after you are able to store and retrieve data without loss of information, are expected rounding errors due to division (or multiplication by non integer).

例如,如果你的货币格式允许2位小数,并要存储的交易,记录平衡10〜3等份借记你只能将其存储像

For example if your currency format allows 2 decimals and you want to store transaction that records balances a debit of 10 to 3 equal pieces you can only store it like

10.00  
-3.33  
-3.33  
-3.33  

-0.01 

(舍入误差)

(rounding error)

这是预期的问题得到照顾,如果你希望你的帐户平衡。这种情况主要是介绍了师(或乘以非整数有很多显著位数字)。

This is expected problem that will occur regardless of the data type storage choice and that needs to be taken care of if you want your accounts to balance. This situation is mainly introduced by division (or by multiplication by non integers that have many significant digits).

应对方法之一是核实,如果经过这样的操作,你的数据结余识别允许取整差异,而不是错误的情况。

One way to deal with this is to verify if your data balances after such operations and recognize the allowed rounding difference as opposed to an error situation.

编辑: 作为参考文献,这个看起来有趣的并不算长,很担心广大观众与有趣的场景。

As for references to literature, this one seems interesting and not too long and concerns quite wide audience with interesting scenarios.

这篇关于常见的策略来处理货币密集软舍入误差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆