Skip to content

Instantly share code, notes, and snippets.

@giventofly
Created November 5, 2021 12:29
Show Gist options
  • Save giventofly/017caefe2b4d936c48f9d0e973c79158 to your computer and use it in GitHub Desktop.
Save giventofly/017caefe2b4d936c48f9d0e973c79158 to your computer and use it in GitHub Desktop.
php truncate number
<?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