Dear Stackoverflowers,
I would like to know what solutions you can solve for the following problem:
This is what I have:
13.90 5.03 7.06 2.51
This is what I want:
13.90 5.05 7.05 2.50
Basically: I want to combine the currency on a commercial basis. The last decimal place can only be rounded to 5 or 10 (adding one to the first digit) or rounded to 5 or 0.
The general formula for rounding to the nearest x :
x
round(input / x) * x
And an example of your use case:
round(5.03 / .05) * .05 = round(100.6) * .05 = 101 * .05 = 5.05
<?php $int = 5.03; $int *= 20; $int = ceil($int); $int /= 20; echo $int;
You just need to determine the rounding resolution by multiplying the number (and then by dividing it again). This is a simple math problem.
Source: https://habr.com/ru/post/1403735/More articles:LEDA v / s graph Boost Graph library - boost-graphCreating objects in python - pythonImprove general factory-type patterns to more SOLID-oriented? - designProblems compiling an iOS 5 application using Google Analytics / GANTracker - iphoneGetting the Windows timezone index using TimeZoneInfo.GetSystemTimeZones (); - timezoneInstall Visual Studio Extension - .netReorganize directory structure with Mercurial - mercurialwhen is memory a byte or an address and why is memoryHow to always break a block in Verilog? - loopshow to reuse cUrl context after executing a PUT request in PHP? - phpAll Articles