Round decimal don't work
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Round decimal don't work
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
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
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
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
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?
I know, it's a typo posting on the forum

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
Hi Josep,
well, that would have been too easy, right?
Sorry, no idea how to workaround this, if possible at all.
Best
Klaus
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
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:
Craig Newman
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
Re: Round decimal don't work
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).

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
shiftLock happens