PHP Number Conversions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

PHP Number Conversions

Post by amir »

I am looking to have a script that can convert numbers like 1,123,000,567 to something like 1.23B. I will need this script to cover

K=thousands,
M=Millions,
B=Billions,
T=Trillions,
Q=quadrillions,
U=quintillion
S=sextillion
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Well, your blocks would indicate that it won't be a native number, so a simple floor((strlen($foo) + 3) / 4) will tell you which notch it falls in, then a substr() can perform the last bit.
Post Reply