Jump to content

Is there a simple way to convert decimal into money?


johnsmith153

Recommended Posts

I always mess around with this with some long winded process.

 

But if I am adding amounts together - ie

$1.02

$1.05

$2.33

etc....

 

and if when adding these values up I get something like 4.40 - then php will store as 4.4

 

How would I ensure it shows 4.40 without my long-winded script?

 

ie I dont want to show the user:

$4.4

$4.42

$3

 

I want them to see

 

$4.40

$4.42

$3.00

or look at the money_format() function, depending on the version of PHP that you're running

 

 

 

Note that it's also useful to hold all monetary values as integer cents rather than float dollars. That way, you're doing integer mathematics rather than floating point mathematics when summing up values or calculating tax, and you'll be less susceptible to rounding errors

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.