Skip to content

Instantly share code, notes, and snippets.

@yoosinpaddy
Created May 11, 2022 02:40
Show Gist options
  • Save yoosinpaddy/66f53ccea0c829b1f8862ede7fdf995f to your computer and use it in GitHub Desktop.
Save yoosinpaddy/66f53ccea0c829b1f8862ede7fdf995f to your computer and use it in GitHub Desktop.
Format number add k for more than 1000
public function formatNumber($number)
{
// add k format
if ($number >= 1000 && $number < 1000000) {
$number = number_format($number / 1000, 1) . 'k';
} elseif ($number >= 1000000) {
$number = number_format($number / 1000000, 1) . 'm';
}
return number_format($number, 2, '.', ',');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment