I am trying to get money to display correctly with the decimal points in the right place.

I have read the PHP manual, but just don't get it.

I want to do 2 things:

1: if someone types in 123.23 -> I want to remove the '.' (so it ends up being 12323) and store it in a database.

2: when I get it out of my database -> I want to add back in the '.' (so it ends up being 123.23 again) and display that.

How do I do that?

Thanks for you help

Why do you remove . while storing? any purpose?

Why do you remove . while storing? any purpose?

So it can be stored as a INT. and I also need to work some stuff out from the number, so it needs to be stored in cents.

I actually figured out how to remove it. by doing str_replace(".", "", $var);

but am still confused how to get it back in there?



I just divided it by 100 and bang. that does the trick.

Don't know why I diddn't think of that before.

Thanks for your help.


Yeah thats cool, divided by 100. one more thing you should know when 12.325, then it would be divided by 1000 and 1232.5 by 10 etc. So make the logic somewhat global. Hope you understand.