Numeric Accuracy Issue

Hi

I have a field in a document which I am rounding by using:

Int(1000 * doc.field(0) + 0.5) / 1000

(which is a more stable rounding formula than round())

This seems to work fine 99.9999% of the time, but I’ve hit an issue on a document where the field value is 3.2325

Using the above code, the correct result is 3.233

If I use a hard coded value in the code, LS returns that value. However, if I pull the value out the field in this one document, it returns 3.232

Looking via document properties, the value is exactly 3.2325, no other dps.

THe only way I’ve been able to fix it is to use

Cdbl(Cstr(doc.field(0)))

to get it to somehow reinitialise the value to exactly 3.2325

is this expected behaviour???

THanks

Kiers

Subject: Numeric Accuracy Issue

more info:

turns out that the value in the field was created using

rate = 15/26

value = (5603 * rate) / 1000

it shows as exactly 3.2325 (even on a calculator), but I guess that notes is using some other accuracy.

If you add a field with that value (say in formula) the roudning is fine - there’s something about the number domino is actually storing

Any feedback would be much appreciated

Cheers

K

Subject: RE: Numeric Accuracy Issue

Floating Point Calcuation is a known issue.

http://www-10.lotus.com/ldd/nd6forum.nsf/Search?SearchView&Query=floating%20and%20point&SearchOrder=0&Start=1&Count=100

cheers !!

Ashish

Subject: RE: Numeric Accuracy Issue

Ah, but from the help file:

A number field can store up to 8 non-zero decimal digits without loss of precision. Notes implements floating point arithmetic using the IEEE64 industry standard. In cases where a user enters more than 8 non-zero decimal digits, rounding may occur and the number may display and be stored differently from the number the user entered.

I’m only using 5 decimal digits, so why the loss of precision?