[ create a new paste ] login | about

Link: http://codepad.org/RAOyBCuY    [ raw code | output | fork ]

PHP, pasted on Feb 20:
1
2
3
4
5
6
7
8
9
10
11
12
<?php

function roundDown($decimal, $precision)
{
    $fraction = substr($decimal - floor($decimal), 2, $precision); // calculates the decimal places to $precision length
    $newDecimal = floor($decimal). '.' .$fraction; // reconstructs decimal with new decimal places
    
    return floatval($newDecimal);
}

echo roundDown(345.3467542, 5);
?>


Output:
1
345.34675


Create a new paste based on this one


Comments: