문제

I have a trouble with editing of Floats in Grails app. I store a latitude information in my domain class with scale defined:

class Location {
   Float latitude
   ...

   static constraints = {
      latitude(scale:15)
   }

Therefore my scaffolded views shows 15 digits precision. However, I can edit only 6 digits after decimal point (if I change 7th digit position, nothing happens). Example: 1. Original: 12.123456789, edit: 12.123450789 - works fine 2. Original: 12.123456789, edit: 12.123456089 - doesn't work, stores previous value

I use H2 DB for testing. I think this is a problem of Grails or Gorm, because the value is stored in DB but "small" number change is not recognized by Grails. Any workround?:-)

도움이 되었습니까?

해결책

Float only has about 7 decimal digits of precision, everything beyond that is artifacts of the internal binary fraction representation. You probably want to use BigDecimal instead.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top