Reputation: 6289
I'm facing some problems binding request parameters to a BigDecimal field in a domain class.
When I type in 25.75 in the duration field, the data is serialized correctly and the duration is passed to the controller in the request with correct precision.
Controller action:
def save() {
// params.duration is 25.75 (debugged and printed to the console)
def entry = new Entry(params)
// entry.duration is now 25
// the precision is lost..
// 125.25 converts to 125
// 1.75 converts to 1
...
}
The domain class:
class Entry {
BigDecimal duration
static constraints = {
duration(min: 0.01G, max: 168.00G, scale: 2)
}
}
The column type in MySQL database is DECIMAL(5,2).
Am I missing something apparent?
EDIT: Using Grails version 2.2.0.
Upvotes: 1
Views: 967
Reputation: 1376
What is your locale/browser language? Number parsing is locale dependent. So, if decimal separator for your locale is "," (comma) instead of ".", then you will get integer numbers after data binding (as you described). Try to change your locale to "en" and check again.
Upvotes: 2