Rounding in LiveCode vs Excel
Andreas Bergendal
andreas.bergendal at gmail.com
Sun Jan 9 15:49:27 EST 2022
Hi all,
TLDR;
In LC:
round(0.5,0) = 1 (Excel agrees)
round(5,-1) = 0 (Excel disagrees and makes that 10!)
I agree with Excel, I want the latter rounded to 10, not 0. Is LC doing it ’wrong’ and if so, why?
Long version:
I’m building software for a client that will do some calculations that are currently done in Excel. They want most amounts rounded off by hundred, so e.g. 1049 is rounded to 1000 and 1050 is rounded to 1100 etc.
In Excel they would use this formula structure: ROUND(1050/100;0)*100 for which Excel returns 1100. I pointed out that ROUND(1050;-2) would give the same result, which they were unaware of. In Excel it does.
So, I thought I’d be smart and use the shorter form in LiveCode: round(1050,-2)
Astonishingly though, for that LiveCode returns 1000.
While round(1050/100,0)*100 returns 1100 also in LiveCode, which is what we want.
So I ended up having to use the cumbersome, long version in LiveCode to get what Excel gives in both versions.
Is LiveCode (or Excel) doing it ’wrong’, or what is going on?
Why does LiveCode round decimals with one logic and integers with another?
/Andreas
More information about the use-livecode
mailing list