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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.