Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- round(3.78 * 5) / 5 = 3.8
- function roundToNearestFraction( $number, $fractionAsDecimal )
- {
- $factor = 1 / $fractionAsDecimal;
- return round( $number * $factor ) / $factor;
- }
- // Round to nearest fifth
- echo roundToNearestFraction( 3.78, 1/5 );
- // Round to nearest third
- echo roundToNearestFraction( 3.78, 1/3 );
- function round2($original) {
- $times5 = $original * 5;
- return round($times5) / 5;
- }
Add Comment
Please, Sign In to add comment