Best practice to represent Money (value + currency) in Grails

谁说我不能喝 提交于 2019-12-03 11:56:28

You might want to take a look a the Currencies plugin. It provides a Money class for holding monetary amounts of differing currencies. They can be embedded into domain classes like so:

class CustomerTransaction {
    Date date = new Date()
    Money amount

    static embedded = ['money']
}
Peter

You should use BigDecimal. Groovy and Grails has excellent native support for it as a datatype on GORM domain classes as well. For reasoning behind using it, see here

What is the best data type to use for money in java app?

Use the JScience library. It's just a shame it's not in a Maven repo yet, and doesn't have a Groovy wrapper to make it Groovier (TM).

If you want to have also live exchage rates updates then following plugin could help https://grails.org/ExchangeRates+Plugin all rates are pulled from Yahoo Finance.

since the original answer seems to be outdated, you might want to take a look at the money-plugin which is fresh and currently maintained.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!