Please read up on these functions:
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Ceil
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Floor
and these three:
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Round
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/RoundDown
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/RoundUp
There are many ways to 'round' numbers. And then there is "bankers" rounding:
https://en.wiktionary.org/wiki/bankers'_rounding
Each has an application that it is best suited for. None of them are really interchangeable.
from your example, 3727.49 should round down to 3725.
you can try roundUp to get your preferred answer of 3730, but asking for round to get you that answer will not work.
@SleepyZ 's answer :
Code:
AddLabel(1, Round((price / 5), 0) * 5);
does provide the best way to round to the
nearest multiple of 5.
Perhaps it is illustrative to see some results of different rounding:
AddLabel(1, Round((price / 5), 0) * 5);
--> 3725
AddLabel(1, RoundDown((price / 5), 0) * 5);
--> 3725
AddLabel(1, RoundUp((price / 5), 0) * 5);
--> 3730
AddLabel(yes, Round(price, 2 ));
--> 3727.49
AddLabel(yes, Round(price, 1 ));
--> 3727.5
AddLabel(yes, Round(price, 0 ));
--> 3727
AddLabel(yes, Round(price, -1 ));
--> 3730
AddLabel(yes, Round(price, -2 ));
--> 3700
Your example, rounding 27.49 up to 30 by thinking that the .49 rounds
up to .5 and then .5 rounds up again to 30 is called double rounding, and is not generally employed by algorithms. The algorithm looks at the 27.4 and decides that .4 rounds down, and so 27.49 rounds
down to 27 rather than
up to 28 and therefore your request to get to the nearest 5 is based on 27 (which goes down) rather than 28 (which would go up).
This is probably a lot longer an answer than you wanted, but I spend a lot of time thinking about how different programs and databases work with rounding. And don't ask me to explain MS Excel does it. I don't want to think about it!!! ;-)
-mashume