I was wondering if someone could tell me how to properly strip and add comas to numbers. I currently have numbers being entered into my database without comas.
Can someone show me a good way to make sure that the info being entered in is a number and how to strip the variable leaving only numbers. Then properly adding comas where they should be. I am referring to the money system. Here are some possible results:
12,583,573
or
22,684,593.85
or
1,348.21
Not sure how to google this one. Thanks!
How to strip variable and add comas where needed?
Moderator: General Moderators
Re: How to strip variable and add comas where needed?
Strip everything but digits and decimals:
For formatting, check number_format() or, perhaps better, money_format()
Code: Select all
$input = preg_replace( '/[^\d\.]/', '', $input );Re: How to strip variable and add comas where needed?
Oh ok, thanks once again 4 your help!!
Cheers!
Cheers!