Search code examples
coldfusioncoldfusion-9

understanding precision and scale on a property


property name="poiLat" length="60" ormtype="big_decimal" persistent=true precision="16" scale="14" default="0" hint="";

I don't understand precision or scale correctly. Using the property above why would '1' give an error and '2' be accepted? what should I change it to to accept '1'

1 ) -118.27 = error

2) -18.27 = ok


Solution

  • Scale refers the number of digits to the right of the decimal place. If you have precision 16 and scale 14, you can only have 2 digits to the left of the decimal place, so

    18.12345678901234 = ok 
    118.27 = error
    

    Try:

    precision="16" scale="13" 
    

    That will allow 118.1234567890123, but that is a lot of decimal places. How many do you really need?

    precision="16" scale="4"
    

    Will allow 123456789012.1234