Question

I have a form that asks for money entered and would like to have it formatted correctly with $, commas every 3 places, and no decimals unless applicable. The trouble is that some users enters them correctly while others do not. How do I check in php to see if this number is in the proper format and if it is not, adjust it accordingly. I've already placed the $ to precede the number, just need help with commas and decimal places.

I've heard it's easier to use number_format rather than money_format. Is there a benefit to use one over the other?

Was it helpful?

Solution

"some users enters them correctly while others do not"

Check on input and you're done, just use number_format afterwards to format the number as you like.

To use money_format you need to have your locales properly configured, if you're just using $, number format is easier.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top