哪种小数实现适用于股票价格?

huangapple 未分类评论42阅读模式
英文:

Which decimal implementation to use for stock prices?

问题

候选项是:

  • 2 个整数(一个表示比例),
  • 浮点数(在进行计算时要小心使用,因为这种类型本质上不精确,在某些情况下,不精确错误可能会错误地累积),
  • BigDecimal(因为它似乎是Java中处理这种类型的标准方式)

选项一的问题是我懒,不想重新发明轮子,如果有人已经做得比我好,我就不想做了。

选项二和三的问题是:这些不是过度了吗?当这些“10或20个字节和很少的性能开销”被数百万次的股票报价、加法、差异和比较所乘以时,这不会严重影响性能、内存和存储使用吗?

英文:

Candidates are :

  • 2 ints (one indicating scale),
  • float (used with caution when doing calculations as this type is inherently imprecise and in some cases imprecision errors can wrongfully add up),
  • BigDecimal (since it seems to be the standard in java for that type of things)

The problem with option number one is i am lazy and don't want to reinvent wheel if someone has already done it better than me.

The problem with option number two and three are : are those not overkills, and wouldn't those severely impact performance as well as memory and storage usage when those "10 or 20 bytes and little performance overhead" are multiplied by millions of stock quotes, additions, differences, and comparisons.

huangapple
  • 本文由 发表于 2020年4月5日 02:22:08
  • 转载请务必保留本文链接:https://java.coder-hub.com/61032773.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定