Created
November 5, 2021 12:29
-
-
Save giventofly/017caefe2b4d936c48f9d0e973c79158 to your computer and use it in GitHub Desktop.
php truncate number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//https://stackoverflow.com/questions/4668628/truncate-float-numbers-with-php/12710283#12710283 | |
function truncate($val, $f="2"){ | |
if(($p = strpos($val, '.')) !== false) { | |
$val = floatval(substr($val, 0, $p + 1 + $f)); | |
} | |
return $val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment