Hi,
I'm working on a shopping site which takes prices, quantities, etc. and calculates a final cost. I cannot figure out how to get floating point numbers to automatically look like currency, ie. 43.50 as opposed to 43.5. I've spent quite a bit of time researching to no avail, so now I'm turning to the forum. Can anyone help? Hope this can be of use to others out there, too.
Thanks.
How do I get floating point numbers to work like currency?
Moderator: General Moderators
-
jtonsfeldt
- Forum Newbie
- Posts: 3
- Joined: Mon Nov 01, 2004 2:30 pm
look at number_format() you should.
Re: How do I get floating point numbers to work like currenc
*LOOKING* like currency is easy. Use number_format as Burrito suggested.jtonsfeldt wrote:I cannot figure out how to get floating point numbers to automatically look like currency, ie. 43.50 as opposed to 43.5.
However, the reason it LOOKS different is because it *is* different. You are probably storing them as a float. Floats don't guarantee precision, in fact, just the opposite. For currency, you should be using NUMBER or DECIMAL, where the values are stored literally and with high-precision.