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

后端 未结 5 1264
逝去的感伤
逝去的感伤 2021-02-14 17:01

I\'m not much familiar to Java Currency type, and how it being used in Grails. Though, I\'m yet to use it, I saw a tag to use in the views.

相关标签:
5条回答
  • 2021-02-14 17:02

    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).

    0 讨论(0)
  • 2021-02-14 17:08

    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?

    0 讨论(0)
  • 2021-02-14 17:11

    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.

    0 讨论(0)
  • 2021-02-14 17:13

    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.

    0 讨论(0)
  • 2021-02-14 17:14

    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']
    }
    
    0 讨论(0)
提交回复
热议问题