Jump to content

change a number like 250,000 into 250K


jwk811

Recommended Posts

if you number does not have commas in it:
[code]<?php
$ext = ''; //initialize
if (($num / 1000000) >= 1) { //test for millions
    $num = $num / 1000000;
    $ext = 'MIL';
} else if (($num / 1000) >= 1) { //test for thousands
    $num = $num / 1000;
    $ext = 'K';
}
echo number_format($num) . $ext; //number_format() adds commas
?>[/code]
here ya go... i just made this for ya...

[code]
<?
function bignumbers($i){
if(strlen($i)<=3) return $i;
$a=array('','K','Mil');
$i=explode(",", $i);
$c=count($i);
return $i[0].$a[$c-1];
}

echo bignumbers('1,000,000');
echo bignumbers('1,000');
echo bignumbers('1');
?>
[/code]
[code]
function bignumbers($i){
if(strlen($i)<=3) return $i;
if(strpos(",",$i)===false) $i=number_format($i);
$a=array('','K','M');
$i=explode(",", $i);
$c=count($i);
return $i[0].$a[$c-1];
}

echo bignumbers('100000');
echo bignumbers('100,000');
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.