Reputation: 658
I have a Grails application and I want to save a number with decimal places, e.g. 902.11
. In my app, I use Czech locale, so the decimal point is represented as comma "," instead of point ".". But in the browser I want to do some calculations by Javascript, so the decimal point must be represented by ".".
Is there a solution so I can customize the Czech locale in my application so it will use the "." instead of ","? Or is there any other solution to this problem?
Upvotes: 0
Views: 1319
Reputation: 1576
For reference:
formatNumber will work when you write the value out into the page, but Lojza probably wanted to get the number back to the controller which is not straightforward since the Grails data-binder is locale specific, so it will expect the number to be formatted according to the Czech locale instead of the base JS format.
You can either override the binder value converter which will be global for your application (may not what you want), or use a command object and retrieve the number value into a String attribute of the command object, so that Grails will not try to apply any number parsing on it. Then you manually convert this string into number according to the base JS format.
Upvotes: 0
Reputation: 29619
You should use the formatNumber tag and specify a locale that uses dots for decimal places, e.g.
<script ...>
var someNumber = <g:formatNumber number="${myNumber}" locale="en" />;
// ... do some javascript calculations
</script>
Upvotes: 2