Problem with precision and scale in new field

4080
16
07-18-2016 12:28 PM
Md_YousufReja
New Contributor

Hello GeoNet community,

I have a question regarding precision and scale of a new field. I am working on making a new field where I need total of 18 digits including 8 digits after decimal. For example the math is

900000000 + 1111*10000 + 1111*1 + 11111111/100000000

I need the result is 911111111.11111111

But, it shows 911111111.11111116

FYI, I have used Double and changed the precision and scale when I add the field. I will be appreciated if anyone has some ideas to explore.

Thanks

Reja

0 Kudos
16 Replies
AbdullahAnter
Occasional Contributor III

In attribute table

right click on the top of the field that you want to set specific precision . and click on properties

1.png

Inside Field Properties window. click on dots icon  ( ... ) it is beside Numeric.

2.png

choose from The left Numeric, then choose number of decimal places . and set it to be 8 as you want. 

3.png

Md_YousufReja
New Contributor

Thanks Anter! I did this part too. However, the problem is still unsolved. I don't know why this is rounding up.

0 Kudos
AbdullahAnter
Occasional Contributor III

you said " I need the result is 911111111.11111111

But, it shows 911111111.11111116"

Both precision is 8

The difference in value not in precision.

0 Kudos
Md_YousufReja
New Contributor

No, actually the scale is 8, precision is 17. Do you have any idea then why the value is changed as I used the scale is 8?

0 Kudos
RichardFairhurst
MVP Honored Contributor

I believe  the maximum number of digits stored internally in a double is 17 digits, so you may have exceeded the limits of what it is capable of displaying reliably.  At least this is true in .Net.

System.Double

"Because some numbers cannot be represented exactly as fractional binary values, floating-point numbers can only approximate real numbers.

All floating-point numbers also have a limited number of significant digits, which also determines how accurately a floating-point value approximates a real number. A Double value has up to 15 decimal digits of precision, although a maximum of 17 digits is maintained internally. "

AbdullahAnter
Occasional Contributor III

I calculate the same Yusuf math in my calculator

the result not exceed  8 decimal digits of precision.

the result is 911111111.11111111

0 Kudos
AbdullahAnter
Occasional Contributor III

Yusuf, How did you change the scale?

0 Kudos
DanPatterson_Retired
MVP Emeritus

You have reached the limits of floating point precision.  The only other build in math module that support higher representation is Python's Decimal class and I think the mpmath module... both of which can't be used in esri products.  You have an alternate solution if this is purely for display purposes... that is to concatenate string representations of the integer and decimal portions of the number.  Your number is being represented as best it can and won't affect calculations

91111111.1111111

>>> a = 911111111.11111111

>>> a

911111111.1111112

>>> a-a

0.0

AbdullahAnter
Occasional Contributor III

Dan, your viewpoint might to be right, I also thought about that .

But

Md Yousuf Reja, wrote in the end of result number 6 not 2.

mdyousufreja wrote:

Hello GeoNet community,

I have a question regarding precision and scale of a new field. I am working on making a new field where I need total of 18 digits including 8 digits after decimal. For example the math is

900000000 + 1111*10000 + 1111*1 + 11111111/100000000

I need the result is 911111111.11111111

But, it shows 911111111.11111116

0 Kudos