Results 1 to 5 of 5

Thread: @DecimalMin("0.1") does not work properly

  1. #1

    Default @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?

  2. #2
    Join Date
    Aug 2010
    Location
    Brazil
    Posts
    9

    Default

    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.

  3. #3

    Default

    Interesting - guess I need to dig further to see where the validation actually happens.

  4. #4
    Join Date
    Aug 2010
    Location
    Brazil
    Posts
    9

    Default

    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) .."

  5. #5

    Default

    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
  •