Page 1 of 1
Round decimal don't work
Posted: Tue Oct 18, 2016 9:32 am
by JosepM
Hi,
I have a big problem with the round function.
I'm with a old version, LiveCode 4.6.4
Theoretically the round function must make a financial rounding, ie, if the decimal part ends in 5, should increase one up.
round (398,545.2) -> 398.55 right?
Any solution or how patch it?
Salut,
Josep M
Re: Round decimal don't work
Posted: Tue Oct 18, 2016 9:47 am
by Klaus
Hi Josep,
you are mixing COMMA and DOT here!
THIS: put round (398,545.2) -> gives an error in LC 8.x
BUT: put round (398.545,2) -> 398,55
LC is "speaking english" so the DOT is used as the decimal delimiter and
the comma to separate the PARAMETER from the data in this function.
Best
Klaus
Re: Round decimal don't work
Posted: Tue Oct 18, 2016 9:55 am
by JosepM
Hi,
I know, it's a typo posting on the forum

sorry
With 4.6.4 don't work, with 6.6.2 work correct.
On 4.6.4 the result is 398.54, don't up
Any solution?
Re: Round decimal don't work
Posted: Tue Oct 18, 2016 1:53 pm
by Klaus
Hi Josep,
well, that would have been too easy, right?
Sorry, no idea how to workaround this, if possible at all.
Best
Klaus
Re: Round decimal don't work
Posted: Tue Oct 18, 2016 1:58 pm
by dunbarx
Hi.
Perhaps you are referring to the HyperTalk way of rounding, which was NOT the financial way, where the integer part determined upward or downward rounding when the decimal part was halfway between?
But LC has another function "statRound", and you can use this if you wish.
Hypertalk recommended this to always round up:
Code: Select all
function roundUp var
if var < 0 then return trunc(var - 0.5) else return trunc(var + 0.5)
end roundup
Craig Newman
Re: Round decimal don't work
Posted: Tue Oct 18, 2016 8:33 pm
by [-hh]
Below the version of Craig, for Cents. He's thinking in integers with money

Works in every version of LC (more correctly: in every version I know).
Code: Select all
-- input: any number
-- output: rounded and formatted to two decimals
-- rounds positive up, negative down,
function financialRound myNum
if myNum < 0 then
put trunc(100*myNum-0.5) into rslt
else
put trunc(100*myNum+0.5) into rslt
end if
put "." after char -3 of rslt
return rslt
end financialRound