Announcement Announcement Module
No announcement yet.
grails scale constraint stripping decimals Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • grails scale constraint stripping decimals

    (Using Grails 1.3.4.)
    I have a field defined as: Float latitude
    I have a constraint: latitude(blank: false, range:-360.0f..360.0f, scale:6)
    The Oracle 10g field is defined as: NUMBER(10,6)

    When I enter a value in Create or Edit, the correct value gets to the database. However, it never displays correctly in Show. If I enter 10.1234567 and update, 10.123457 is in the database but 10.123 displays in Show.

    If I Edit, the value shows as 10.123, and if I update without modifying it, 10.123 will be stored in the database, replacing 10.123457 even though I never touched that field.

    If I edit the value to 10.456789, but leave another required field blank, the resulting Edit screen with the error message displays the value as 10.457.

    Why is Grails continually rounding the value to 3 digits? I tried the field as a Double as well, but same results. I thought maybe it was Oracle, but I tried it with the default dev database, and same result. I thought maybe it was the 'range', but I took that off with the same result.

  • #2
    This is probably a result of the property editor used. You can register your own property editor for numbers. The answer to this StackOverflow question shows you how to do it for dates, but it should be straightforward to extend for numbers:


    • #3
      I understand your comment about setting up a custom property editor, and appreciate the tip. This is out-of-the-box Grails install - is the 'scale' constraint essentially useless? Should scale:6 ensure 6-decimal display, or is that only to trim any values sent to the database to 6? For now I'll assume its purpose is the later and proceed with the custom format.

      BTW, I've got "Grails in Action" and it's a great book. Thanks.


      • #4
        Glad you like the book!

        I wouldn't say that the 'scale' constraint is useless, but it obviously doesn't influence the scaffolding. I would raise a JIRA issue to make scaffolding 'scale'-aware.