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

Recommended Answers

All 5 Replies

Member Avatar for rajarajan2017

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?

thanks

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

Member Avatar for rajarajan2017

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.