Rounding to predefined decimal places in ruby using floor or modulo

If you don’t have rounding function available like in older versions of ruby, you can do rounding by using floor and modulo functions


Trough floor ( takes only integer part) function it could be done so :

if (shm - (floor(shm/100 000)*100000)) >= 50000 ; then
   shmall= ((floor(shm/100 000)+1)*100 000)
   shmall=(floor(shm/100 000)*100 000)

Trough modulo (gives reminder of division):

if mod(shm/100 000) > 50000 ; then
   shmall= shm+ (100 000-mod(shm/100 000))
   shmall= shm- mod(shm/100 000)


If you found this useful, say thanks, click on some banners or donate, I can always use some beer money.