Forum Moderators: coopster

Message Too Old, No Replies

Integer Manipulation

Rounding, dealing with commas, etc.

         

briesm

1:11 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



Hey all, first of all, thanks for all the help! YOu guys are quick to respond and have helped me with quite a few dilemnas. So I'm wondering if any of you know any code that would convert a number that was entered with commas e.g. 1,000 to a calculation friendly number: 1000

Thanks in advance :>)

briesm

1:41 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



Also, i'm trying to think how I could do the reverse and take a number like 1000000 and output 1,000,000

EDIT:
I think I figured out how to remove commas, easy enough...

$amount = str_replace (',', '', $amount);

To add commas:

number_format($number, 2);

mcibor

3:31 pm on Jun 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, number format will do.

it's a very good function, because you can change the thousand delimitor and fraction to whatever you wish:

$number = number_format($number, $how_many_numbers_after_integer, $fraction, $thousands);

in different countries these parameters differ.

Michal Cibor