Rounding in LiveCode vs Excel
Phil Davis
phil at pdslabs.net
Sun Jan 9 21:10:31 EST 2022
Will using "statround()" instead of "round()" give you an
Excel-comparable outcome?
Phil Davis
On 1/9/22 12:49 PM, Andreas Bergendal via use-livecode wrote:
> 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
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
--
Phil Davis
503-307-4363
More information about the use-livecode
mailing list