Home Forums Article Discussions Article Discussions by Author Discuss content posted by Hannan Kravitz Round Natural Numbers to the nearest Power of 10 RE: Round Natural Numbers to the nearest Power of 10
May 16, 2017 at 2:04 pm
t.franz - Tuesday, May 16, 2017 2:56 AMWhy do you not use the build in ROUND function?
It takes three parameters:
- the value
- the rounding length (use negative numbers to round to a power of 10, example for 12345: -1 -> = 12350, -2 -> 12300, -3 = 12000
- optional 0 or 1, while the default 0 rounds, while 1 will cut the numbers off;ROUND(12345, -1, 0) = 12350
whileROUND(12345, -1, 1) = 12340
The only benefit of your
function is the easier usage of the direction (up or down), but this could be solved by cutting off the decimals (= rounding down) and adding 10 (or 100 or 1000...) when you want to round up:ROUND(12345, -1, 1) + 10
PS: Bonus points for using an INLINE TABLE VALUE function instead of a scalar function
Thanks!