在企业应用中小数四舍五入策略 [英] Decimal rounding strategies in enterprise applications

查看:111
本文介绍了在企业应用中小数四舍五入策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我想知道的事情进行舍入小数,并将它们存储在数据库中。

Well, I am wondering about a thing with rounding decimals, and storing them in DB.

但问题是这样的:

让我们说我们有一个客户和发票

Let's say we have a customer and a invoice.

发票具有$ 100.495总价(由于某些折扣百分比这不是整数),但是它被示为$ 100.50(四舍五入时,只用在发票打印)。它是存储在DB为$ 100.495价格,这意味着,当顾客使得$ 100.50存款它将具有$ 0.005对帐户额外。如果是圆形的,它会显示为$ 0,但夫妇发票会不断积累,这会出现错误的(虽然它实际上不是)之后。

The invoice has total price of $100.495 (due to some discount percentage which is not integer number), but it is shown as $100.50 (when rounded, just for print on invoice). It is stored in the DB with the price of $100.495, which means that when customer makes a deposit of $100.50 it will have $0.005 extra on the account. If this is rounded, it will appear as $0, but after couple of invoices it would keep accumulating, which would appear wrong (although it actually is not).

什么是最好在此情况下这样做。存储的$ 100.50的值,或保留一切按原样?

What is best to do in this case. Store the value of $100.50, or leave everything as-is?

推荐答案

您应该存储的号码完全按照您希望它是反映在其资产负债。

You should store the number exactly as you want it to be reflected on their balance.

您实际收费客户半分?如果是,它应该反映在DB条目。如果你没有,那么它不应该。

Are you actually charging the customer the half-cent? If you are, it should be reflected in the DB entry. If you're not, then it shouldn't.

不过,除非我每天都张贴应计利息(如Prosper.com为例)我会用货币单位坚持人们可以支付(或撤销)完全相同。

But unless I were posting accrued interest daily (like Prosper.com for example) I would stick with units of currency that people can pay (or withdraw) exactly.

这篇关于在企业应用中小数四舍五入策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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