{"id":640,"date":"2016-05-05T14:18:42","date_gmt":"2016-05-05T11:18:42","guid":{"rendered":"http:\/\/www.bashpi.org\/?page_id=640"},"modified":"2020-12-03T17:37:50","modified_gmt":"2020-12-03T15:37:50","slug":"rounding-to-predefined-decimal-places-using-floor-or-modulo","status":"publish","type":"page","link":"https:\/\/www.bashpi.org\/?page_id=640","title":{"rendered":"Rounding to predefined decimal places in ruby using floor or modulo"},"content":{"rendered":"<p>If you don&#8217;t have rounding function available like in older versions of ruby, you can do rounding by using floor and modulo functions<\/p>\n<p>&nbsp;<\/p>\n<pre>Trough floor ( takes only integer part) function it could be done so :\n\nif (shm - (floor(shm\/100 000)*100000)) &gt;= 50000 ; then\n   shmall= ((floor(shm\/100 000)+1)*100 000)\nelse\n   shmall=(floor(shm\/100 000)*100 000)\nfi\n\nTrough modulo (gives reminder of division):\n\nif mod(shm\/100 000) &gt; 50000 ; then\n   shmall= shm+ (100 000-mod(shm\/100 000))\nelse\n   shmall= shm- mod(shm\/100 000)\nfi<\/pre>\n<p>&nbsp;<\/p>\n<p>If you found this useful, say thanks, click on some banners or <a href=\"http:\/\/www.bashpi.org\/?page_id=105\">donate<\/a>, I can always use some beer money.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you don&#8217;t have rounding function available like in older versions of ruby, you can do rounding by using floor and modulo functions &nbsp; Trough floor ( takes only integer part) function it could be done so : if (shm &#8211; (floor(shm\/100 000)*100000)) &gt;= 50000 ; then shmall= ((floor(shm\/100 000)+1)*100 000) else shmall=(floor(shm\/100 000)*100 000) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":397,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-640","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages\/640","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=640"}],"version-history":[{"count":3,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages\/640\/revisions"}],"predecessor-version":[{"id":775,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages\/640\/revisions\/775"}],"up":[{"embeddable":true,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages\/397"}],"wp:attachment":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}