I have this problem with the function trunc.
Having 10,995 and wanting to get 10.99 used trunc with numberformat this:
Code: Select all
set the numberFormat to "#.00"
put trunc((7.33*12)/8) into temp
How can I get just 10.99?
Thanks
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Code: Select all
set the numberFormat to "#.00"
put trunc((7.33*12)/8) into temp
Code: Select all
on mouseUp
set the numberFormat to "#.##"
put statRound(((7.33*12)/8)*1000)/1000 --into temp
end mouseUp
Guten abend Klaus,Klaus wrote:Buonasera Alessio,
well, as the dictionary states:
...
The trunc function returns an integer.
...
So this will NEVER work for you![]()
Try the round() function!
Best
Klaus
Code: Select all
put temp - (temp mod .01) into temp
It Works.FourthWorld wrote:I don't believe you can, at least not with conventional rounding rules, because the output of the equation is 10.995 and 5 rounds up, causing each of the 9s to the left to increment, leaving you with the whole number 11.
But since you've added trunc, as Klaus noted it's removing all of the fractional portion and leaving you with 10.
If you want an accurate answer (at least according to conventional rounding rules) within two decimal places, removing trunc will do it, leaving you with 11.00.
But if you want to get 10.99 from an answer that's 10.995, the only way I can see to do that would be to convert the whole thing to an integer, use statRound for more nuanced rounding, and then reduce it back to a fractional number, e.g.:Code: Select all
on mouseUp set the numberFormat to "#.##" put statRound(((7.33*12)/8)*1000)/1000 --into temp end mouseUp
Probably exists, but I have not been able to find it with round()dunbarx wrote:Hi.
Did you really mean "10,995" and "10.99"? That is, a comma in the first number, and a decimal point in the second? I assume you meant a decimal in both.
But in that case, the "round" function allows you to set the resulting precision, either before or after the decimal point. It should be a one stop solution.
Craig Newman
It work!snm wrote:Maybe trunc ( 10.995 * 100 ) / 100 is what you are looking for?
Marek