Domanda

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?:-)

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top