Take the 2-minute tour ×

I want my number format like this:

1000 = 1k

10500 = 10.5k

1843 = 1.8k

17434 = 17.4k 

But I have no clue how to do that. The language is PHP

Thanks for the help!

share|improve this question

closed as not a real question by Michael Petrotta, moonwave99, Dagon, talonmies, The Shift Exchange Dec 30 '12 at 8:13


You can't expect people to do your homework for you here. What have you tried? –  Reza S Dec 30 '12 at 3:08
It is not that you have no clue, it is just that you have no will. Put some effort when asking questions to the community please. –  moonwave99 Dec 30 '12 at 3:14

3 Answers 3

Try this:

$num = 14600;
if($num >= 1000)
    echo round(($num/1000),1) . 'k';
share|improve this answer
What will be the output when $num = 1000 –  harry Dec 30 '12 at 4:51
edited. that should take care if it. –  abhi.gupta200297 Dec 30 '12 at 4:52

This will fit your need.

$num = 10234;
echo round($num/1000*100)/100.'k';
share|improve this answer
I think this will give a syntax error. Some thing like this " unexpected 'k' " –  harry Dec 30 '12 at 4:58
No, it won't. (Although the code is a bit ugly...) –  Licson Dec 30 '12 at 5:03

This should work for any number.

$num = 1000;
echo round($num / 1000) . "k";
share|improve this answer
unless you think a "k" is 1024... –  Devin Ceartas Dec 30 '12 at 3:10
Thanks, it's perfect if you add round() through it, so it looks like that: round(($num / 1000), 1) . 'k') - Thanks alot! Didn't thought so far at 4AM (my local time). –  hhhhhhhhhhhhhhhhhh Dec 30 '12 at 3:13
@Finn - No problem, you can accept this as the answer by pressing the checkmark –  Jeremy Dec 30 '12 at 3:14
Who dv'd? Why the dv? –  Jeremy Dec 30 '12 at 3:15
