HI
For the community members better educated in maths than me, should the answer in row 4 not be -200?
Regards
Piet
HI
For the community members better educated in maths than me, should the answer in row 4 not be -200?
Regards
Piet
Come to think of it, shouldn’t the answer for row 1 be 136?
There’s three formulas for rounding: RoundUp(), RoundDown(), & RoundTo(). RoundTo will go to the nearest integer. So maybe try using one of the other two to get your desired result?
This works exactly as intended. It rounds to the nearest value that is a multiple of your factor.
Row 1 it round to the nearest of 134 or 135.,
Row 2 it round to the nearest of 130 or 140,
Row 3 it round to the nearest of -130 or -135,
Row 4 it round to the nearest of -100 or -200,
Row 5 it round to the nearest of -130 or -140
For sake of completeness, there are actually 8 Rounding-related formulas in Coda and they all behave in slightly different ways. The Coda School covers each of the 8 rounding formulas in length here
For the sake of simplicity, Standard rounding rules state that anything BELOW 5 will round down and anything ABOVE 5 will round up.
Heres some examples with standard rounding rules
4.9 to the factor of 10 will round → 0
4.9 to the factor of 1 will round → 5
1.49 to the factor of 1 will round → 1
1.499 to the factor of 1 will round → 1
1.5 to the factor of 1 will round → 2
49 to the factor of 100 → 0
50 to the factor of 100 → 100
Round and RoundTo are essentially equivalent in that they follow standard rounding rules, but RoundTo allows you to define a factor.
RoundUp and RoundDown though do NOT follow standard rounding rules. They will always round up/down so:
Thanks guys,
I had a short circuit - wanted it to calc the next largest, rather than nearest…
I’ll clean my glasses.
P
And, [could] rounded numbers be impacted by the infamous javascript floating point error as well?
Very good article. I’ve had a few problems with floating point errors in Coda.
I’m going to use this trick below from now on.
Instead of:
This isn’t specific to coda, it’s a consequence of the binary floating-point system, it’s seen in every programming language. Here’s a relevant SO thread
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.