|
>> Earlier it was rendered as "12.34". Nice but...
>> When I save the form I get the following validation error: >> Failed to convert property value of type [java.lang.String] to required type >> [float] for property weight; nested exception is >> java.lang.NumberFormatException: For input string: "12,34" > > Thanks for the report. I'll take a look. Unfortunately, it seems that the custom number editor cannot be registered for primitive "float" fields. To be honest, you should be using BigDecimal wherever the user can enter numbers, but it would still be nice if this worked :( Does anyone know whether it's possible to register custom data binders for primitive types? Thanks, Peter --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
> Unfortunately, it seems that the custom number editor cannot be
> registered for primitive "float" fields. To be honest, you should be > using BigDecimal wherever the user can enter numbers, but it would > still be nice if this worked :( Does anyone know whether it's possible > to register custom data binders for primitive types? OK, I worked it out - now fixed. Please note that you should still use BigDecimal otherwise the value entered by the user may not be the value shown by the application! Cheers, Peter --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Hi Peter,
what about doubles? Could you elaborate on this float vs. BigDecimal issue? Thanks, Dimo Peter Ledbrook wrote: >> Unfortunately, it seems that the custom number editor cannot be >> registered for primitive "float" fields. To be honest, you should be >> using BigDecimal wherever the user can enter numbers, but it would >> still be nice if this worked :( Does anyone know whether it's possible >> to register custom data binders for primitive types? >> > > OK, I worked it out - now fixed. Please note that you should still use > BigDecimal otherwise the value entered by the user may not be the > value shown by the application! > > Cheers, > > Peter > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
> what about doubles? Could you elaborate on this float vs. BigDecimal issue?
Same with doubles. There are some numbers (such as 1.1 I believe) that cannot be represented exactly by a double. So if you had a double field and the user entered 1.1 into the scaffolded edit page, the show page may display 1.099998 or something like that. If you need exact floating-point representation then you should use BigDecimal. In fact, floating-point literals in Groovy are instances of BigDecimal rather than float or double. If you then need to do some calculations using your floating-point fields, you can convert them to doubles or floats first and then convert them back to BigDecimal for storage. Hope that helps, Peter --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by Dimo Velev
Read up on the care and feeding of floating point numbers, or you're going to have a lot of nasty
surprises if you're using floats/doubles in your code. For instance: 1.0/7.0*7.0 != 1.0 ~~ Robert. Dimo Velev wrote: > Hi Peter, > > what about doubles? Could you elaborate on this float vs. BigDecimal issue? > > Thanks, > Dimo > Peter Ledbrook wrote: >>> Unfortunately, it seems that the custom number editor cannot be >>> registered for primitive "float" fields. To be honest, you should be >>> using BigDecimal wherever the user can enter numbers, but it would >>> still be nice if this worked :( Does anyone know whether it's possible >>> to register custom data binders for primitive types? >>> >> >> OK, I worked it out - now fixed. Please note that you should still use >> BigDecimal otherwise the value entered by the user may not be the >> value shown by the application! >> >> Cheers, >> >> Peter >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > -- ~~ Robert Fischer. Smokejumper Consulting http://smokejumperit.com Enfranchised Mind Blog http://enfranchisedmind.com/blog LinkedIn Profile http://www.linkedin.com/in/robertfischer Twitter Feed http://twitter.com/robertfischer --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
