Skip to content

Instantly share code, notes, and snippets.

View EXayer's full-sized avatar
🧿
Focusing

Vitalii Honcharuk EXayer

🧿
Focusing
  • SoftHouseGroup
  • Vinnytsia, Ukraine
  • 04:51 (UTC +03:00)
  • X @theyseemenot
View GitHub Profile
@EXayer
EXayer / numberAbbreviation.php
Last active February 10, 2021 22:56 — forked from bcole808/numberAbbreviation.php
Shorten large numbers into abbreviations (i.e. 1,500 = 1.5k), (slightly optimized)
<?php
/**
* Shorten large numbers into abbreviations (i.e. 1,500 = 1.5k)
*
* @param int $number Number to shorten
* @return String A number with a symbol
*/
function numberAbbreviation($number) {
$abbrevs = [1000000000000 => 'T', 1000000000 => 'B', 1000000 => 'M', 1000 => 'K', 1 => ''];