Created
September 30, 2013 01:20
-
-
Save luckyshot/6758239 to your computer and use it in GitHub Desktop.
Nice number abbreviation (i.e. 12.5k)
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
function abbreviate_number($num) { | |
if ($num >= pow(10,3) AND $num < pow(10,4)) { | |
return round($num/1000, 1).'k'; | |
}else if ($num >= pow(10,4) AND $num < pow(10,5)) { | |
return round($num/1000, 1).'k'; | |
}else if ($num >= pow(10,5) AND $num < pow(10,6)) { | |
return round($num/1000, 0).'k'; | |
}else if ($num >= pow(10,6) AND $num < pow(10,7)) { | |
return round($num/1000000, 1).'m'; | |
}else if ($num >= pow(10,7) AND $num < pow(10,8)) { | |
return round($num/1000000, 0).'m'; | |
}else if ($num >= pow(10,8)) { | |
return round($num/1000000, 0).'m'; | |
}else{ | |
return $num; | |
} | |
} | |
echo abbreviate_number(123456789); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment