1

I need to get a money value from the user, but the user can type the number in different formats:

1.234.234,78
1234566,26 
123,123,132.12 

I don't know how to treat the variable.

I have to transform that value in Double type but if the user give me a value with "," the program generate an exception, how can I handle this?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Simo
  • 698
  • 1
  • 5
  • 18

2 Answers2

0

If you want to handle money then I recommend you a great grails plugin with many feature for currencies handling and conversions etc.

Have a look at Currency plugin.

Sachin Verma
  • 3,712
  • 10
  • 41
  • 74
0

In your domain static constraints use matches with the regular expression that handles currency format.

Then using java.text.NumberFormat allows you to format double regardless of having comma in the input.

Armaiti
  • 766
  • 3
  • 11