如何在Java中建模一笔钱 [英] How to model an amount of Money in Java
问题描述
任何人都可以推荐使用款式金额的类库或设计模式
Can anybody recommend a class library or a design pattern that models amounts of Money?
我想应该支持:
- 多种货币
- 小数位数
- 数学(尊重某些舍入约定(cfr ie。 />>
- $ / $>
$ {$}
$ - $ / $>
- multiple currencies
- a mechanism to indicate the number of decimals
- math (respecting certain rounding conventions (cfr ie. Banker's Rounding))
- serialisation to and from a String representation
- ... ?
即 19.99 USD 可以序列化为 USD-2-00000001999
(而2表示小数位数)
I.e. 19.99 USD could be serialized into "USD-2-00000001999"
(Whereas 2 indicates the number of decimals)
推荐答案
我会检查 JScience 项目(Jean Marie Dautelle)的#包装描述 =noreferrer>货币模块。
I would check the monetary module from the JScience project (by Jean Marie Dautelle).
根据您的具体需求,Stephen Colebourne开始了 Joda-Money (更专注于项目 [比JScience])。但是还没有完整的版本(0.5年前发布了一年前)。
Depending on your exact needs, Stephen Colebourne started Joda-Money ("a more focussed project" [than JScience]) some time ago. But there is no full release available yet (version 0.5 was released one year ago).
这篇关于如何在Java中建模一笔钱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!