Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PHP fade/mute zeroes in decimals
<?php
function formatBtc($val){
$val = number_format($val, 8); // round to 8 decimal points
$rtval = rtrim($val, "0"); // get rid of zeroes at the end
$x = strlen($val) - strlen($rtval); // get how many zeroes were deleted
if($x > 0){
$rtval .= '<span style="color:#ffffff6f;">'; // start a "faded" <span>
// or try class="text-muted" for bootstrap
for($i = 0;$i < $x;$i++) // add deleted zeroes back
$rtval .= "0";
$rtval .= "</span>";
}
return $rtval;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.