Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 <g:currencySelect> to use in the views. So, how do I represent it in the domain class.

class Money {
BigDecimal value
Currency currency
....
}

or is there a better sol, which compares diff money objects, format according to the locale ( ',' in EU for separator etc)

thanks in advance. Babu.

like image 419
bsr Avatar asked Apr 14 '10 12:04

bsr


1 Answers

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?

like image 150
Peter Avatar answered Oct 10 '22 01:10

Peter