-
May 26th, 2011, 12:11 PM
#1
@DecimalMin("0.1") does not work properly
I realize this is not specifically a Roo question.
I have a field
@DecimalMin("0.1")
private Float distance;
When testing with real data (always a good idea ;-), this field rejects the value 0.5. 1.0 is ok. Anyone have any insight into this?
-
May 27th, 2011, 08:45 AM
#2
I'm experiencing a similar problem. I'm checking if a value is greater than 0.0. @DecimalMin("0.0") and when I test this value against "-0.1", it fails. When I test against "-1.0". It passes.
-
May 27th, 2011, 12:51 PM
#3
Interesting - guess I need to dig further to see where the validation actually happens.
-
May 27th, 2011, 02:47 PM
#4
Found the problem:
Look at line 61 of https://github.com/hibernate/hiberna...ForNumber.java
note that, if your value is not a BigDecimal or BigInteger (like Float or Double) it compares value.longValue() against the ConstraintValue. So, if your constraint value is 0.0 and you pass Float 0.1 to be validate, the line 61 will be executed and you will get 0.1.longValue() that will became 0.0 which is equals to the Constraint Value...
And the API specification on http://jackson.codehaus.org/javadoc/...ecimalMin.html where it says:"..Note that double and float are not supported due to rounding errors (some providers might provide some approximative support) .."
-
May 27th, 2011, 10:54 PM
#5
Good detective work! I will try using BigDecimal, tho in this case, they will all be small decimals
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules