The divisors loop assumes that the next row is 1000 times larger than the current one so I think you’ll have to change the logic here, e.g. keep iterating until the divisor is too big and use the previous one e.g.
if (!isset($divisors)) {
$divisors = array(
pow(10, 0) => '',
pow(10, 3) => 'K', // Thousand
pow(10, 5) => 'L', // Lakh
pow(10, 7) => 'CR', // Crore
);
}
$divisor = 1;
$shorthand = '';
foreach ($divisors as $next_divisor => $next_shorthand) {
if (abs($number) < $next_divisor) {
// Too big; use previous row
break;
}
$divisor = $next_divisor;
$shorthand = $next_shorthand;
}
I’d guess that’s all you need to change. (I don’t know if you need to tell number_format to not use thousands too but hopefully it’ll take that from the locale, and you wouldn’t be showing thousands unless you’ve got 1000+ crore anyway.) Note also that the existing function does not use the $precision parameter.