HELP -> Change 2,500,000.40 to 2500000.00

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
User avatar
pido
Forum Commoner
Posts: 35
Joined: Mon Jan 12, 2004 8:03 am

HELP -> Change 2,500,000.40 to 2500000.00

Post by pido »

How do i change this variable to 2 decimals??? 2,500,010.40 -> 2500010.40
Any idea how I do this??? Thnx... :D
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Re: HELP -> Change 2,500,000.40 to 2500000.00

Post by hawleyjr »

pido wrote:How do i change this variable to 2 decimals??? 2,500,010.40 -> 2500010.40
Any idea how I do this??? Thnx... :D

The number is already two decimals. Do you mean remove the commas?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

check out number_format()
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

It seems like he just wants to get rid of the commata.

Code: Select all

$teh_numbar = '2,500,010.40';

$teh_numbar = round(floatval((str_replace(',', '', $teh_numbar))), 2);
User avatar
pido
Forum Commoner
Posts: 35
Joined: Mon Jan 12, 2004 8:03 am

Post by pido »

YEA!! you rite!!! my bad :oops: how do i do that hawleyjr??
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Code: Select all

$myNumber = '2,500,010.40';
$result = str_replace(',', '', $myNumber);
Post Reply