0

Hi,

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

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by sacarias40
0

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?

thanks

0

WORKED IT OUT..

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.

QWaz

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.