如何在Java中建模一笔钱 [英] How to model an amount of Money in Java

查看:147
本文介绍了如何在Java中建模一笔钱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以推荐使用款式金额类库设计模式

Can anybody recommend a class library or a design pattern that models amounts of Money?

我想应该支持:

  • 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屋!

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