How to "round" a number to the end on certain numbers?

I need a math function / formula / expression to take a number as a parameter and find the smallest number ending in specific digits that are larger than the parameter.

For example, if the final digits should be 88, these are some examples of what I want:

f(0) = 0 f(87) = 88 f(88) = 88 f(89) = 188 //NB: NOT 88*2=176 f(187) = 188 f(188) = 188 f(189) = 288 

etc. You get the idea.

So far I have used a function (in Delphi not implemented by me) that does this:

 function RoundToSpecificEndingDigits(aLength,aModMeasure : double) : double; begin Result := aModMeasure; while Result < aLength do Result := Result + 100; end; 

Now I need a more “mathematical” approach with div and mods and rounds, etc. The reason is because I want to do this in SQL without creating functions.

+1
source share
1 answer

what about the following:

  • count the number of digits you want to round to "88" => n = 2
  • subtract the suffix from your number.
  • round to the nearest 10 ^ n (divide by 10 ^ n, round to an integer, multiply by 10 ^ n)
  • add suffix.

In SQL:

 SELECT CEIL( (num - suffix) / POW(10, LENGTH(suffix)) ) * POW(10, LENGTH(suffix)) + suffix 
+1
source

All Articles