TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Currency rounding rules

10 点作者 fullmetaleng超过 8 年前
Are there any rules about what Rounding Mode and Rounding Increments should be used for different currency types?<p>I am aware of ISO 4217 which specifies the number of minor units (digits after decimal point) that are permitted for known currency types.<p>But, after searching on the internet for more than half-a-day, there seems to be no clear guidance about what Rounding Mode and Rounding Increments should be used for currency types. Does that mean it is up to the application developer to choose the Rounding Mode and Rounding Increments?<p>I was told that there are some laws that mandate certain rounding mechanisms to be used for certain currencies, but unfortunately I couldn&#x27;t find them.

4 条评论

byoung2超过 8 年前
A quick search reveals that the highest precision should be used for storage and calculations, and rounding just for presentation. So it shouldn&#x27;t matter what rounding rule you use for display purposes.<p>I did find this explanation of Euro rounding rules: <a href="http:&#x2F;&#x2F;www.sysmod.com&#x2F;eurofaq.htm#ROUNDING" rel="nofollow">http:&#x2F;&#x2F;www.sysmod.com&#x2F;eurofaq.htm#ROUNDING</a>
评论 #12661582 未加载
shadowwolf007超过 8 年前
The standard rounding for financial applications is typically Banker&#x27;s Rounding, which is another way of describing rounding to the nearest even. E.g. 1.5 rounds up to 2 but 6.5 rounds down to 6. Over the long haul, this method of rounding produces the least amount of error. Some regulations and laws, though, specify different rounding techniques or specific phases in a process where rounding must or must not be performed. Especially critical in things like forex and other trading type applications. In addition to what byoung2 mentioned, Canadian law has specific rounding regulations that change based on what payment method is being used, but (as far as I know) don&#x27;t generally apply to things like interest calculations and stuff like that[1].<p>ISO 4217 works well for display purposes but doesn&#x27;t work for all financial applications. Consider, for example, scenarios involving tax or a product billed based on usage. By rounding off at each processing step, the company could be losing substantial amounts of money. The last two companies I&#x27;ve worked have used varying types of mechanisms for tracking fractions of pennies. In some circumstances, it makes sense to store everything as integers with a separate column to represent precision, but I would probably not do this unless you have a specific use. It&#x27;s a lot of noise and mucks up the source code worse than, say, a BigDecimal or Decimal type. At the current job, we store everything with 6 digits of precision because of the nature of our billing and use Decimal as a reserved type for only money.<p>To be honest, if you have an accounting department you probably want to involve them in these discussions because rounding decisions can have impact on your financial statements and, potentially, any audits that may occur in the future. I&#x27;ve worked on two financially focused applications so far and I would strongly suggest that you build out a very defined and clear way to manipulate money for rounding purposes. Building out those processes in a standardized and well-defined way makes for easy unit tests and also helps those who come in the future understand the decisions made.<p>[1]: <a href="http:&#x2F;&#x2F;www.mint.ca&#x2F;store&#x2F;mint&#x2F;about-the-mint&#x2F;rounding-6900008" rel="nofollow">http:&#x2F;&#x2F;www.mint.ca&#x2F;store&#x2F;mint&#x2F;about-the-mint&#x2F;rounding-690000...</a>
saluki超过 8 年前
We ran in to this on a project recently involving line item currency calculations that were coming up off by pennies vs what the API was calculating.<p>We were directed to use HALF_UP rounding to two decimal places for each calculation.<p><a href="https:&#x2F;&#x2F;docs.oracle.com&#x2F;javase&#x2F;7&#x2F;docs&#x2F;api&#x2F;java&#x2F;math&#x2F;RoundingMode.html" rel="nofollow">https:&#x2F;&#x2F;docs.oracle.com&#x2F;javase&#x2F;7&#x2F;docs&#x2F;api&#x2F;java&#x2F;math&#x2F;Rounding...</a>
brudgers超过 8 年前
Compliance with local currency regulations is probably a hard problem, not just because the regulations may be written in the local language but because their interpretation may vary with time, place and the individual interpreting...and the amount of money involved.<p>Then again, it&#x27;s money so it&#x27;s worth taking seriously and paying for or developing expertise for any project that matters.