Page 1 of 1
Malfunction round()
Posted: Mon Aug 14, 2023 3:25 am
by Piotr D
Hi,
in some cases the function Round() gives wrong result. For example:
0.82*0.15*115.00 = 14.145
but round() of these value:
Round(0.82*0.15*115.00 ,2) gives 14.14 instead 14.15 !!!
Piotr
Re: Malfunction round()
Posted: Mon Aug 14, 2023 3:50 am
by Piotr D
Update:
when you round intermediate results, like:
Round(Round(0.82*0.15,4)*115.00 ,2)
the result is correct: 14.15
Look like it's again the result of a binary representation of the non-integer value (like 14.15 = 14.1499999999999999999...)
Regards
Piotr
Re: Malfunction round()
Posted: Mon Aug 14, 2023 4:40 am
by Wolfgang Ciriack
That is the reason, i use the function roundZ() for some years:
Code: Select all
Function RoundZ(nValue)
Return (Round(Round(nValue, 4), 2))
Re: Malfunction round()
Posted: Tue Aug 15, 2023 2:08 am
by Piotr D
Wolfgang,
these function don't solve problem. For example:
x=14.144966
Round(x,2) will be 14.14
and RoundZ(x) will be 14.45.
To get the correct result of multiple multiplication of a non-integer values, we need round after each multiplication.
Piotr
Re: Malfunction round()
Posted: Tue Aug 15, 2023 2:53 am
by Piotr D
Hi all,
I found that these problem was described under PDR 6678. When I add in ARC file under VERSION:
"FPU_ControlWord" = "626"
this problem was solved.
Regards
Piotr
Re: Malfunction round()
Posted: Tue Aug 15, 2023 11:23 pm
by Piotr D
Hi all,
I found another solution. This easy trick solve the problem
instead Round(x,n) ---> Round(Val(Str(x)),n)
Regards
Piotr