Rounding in LiveCode vs Excel

Tom Glod tom at makeshyft.com
Sun Jan 9 16:59:48 EST 2022


Andreas, thanks this is very interesting and super good to know. Seems a
little bit important.

Thanks, following this thread.

On Sun, Jan 9, 2022 at 3:50 PM Andreas Bergendal via use-livecode <
use-livecode at lists.runrev.com> 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
>


More information about the use-livecode mailing list