PHP fade/mute zeroes in decimals
This file contains 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 | |
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