coco1985 wrote:I have a row type set up as an INT. Whenever I enter the amount, it rounds it and takes the decimals off.
Since integers don't have a fractional/decimal amount, that shouldn't be surprising.
I've always stored money amounts as a DECIMAL column... usually something like DECIMAL(18,2).
coco1985 wrote:I tried setting it to DECIMAL, but then it adds two more decimals.
How did you attempt to INSERT the data?
coco1985 wrote:I tried the number format function and it worked but the cents were still rounded up and came out as 1800.00
If you're referring to using the integer column, then this has nothing to do with number_format(). If the data in your DB gets truncated, then the original value is lost forever and no matter what function you use after you retrieve the data back will be based on the new truncated value.
coco1985 wrote:I don't know if its the best way to do it because only one variable is set up for the number_format.
Er... what do you mean by "set up" ? Variables don't get "set up" for anything... they simply hold values. To that end, you could change this:
$amount = $row['amount'];
// ...
$paid = $row['paid'];
to this:
$amount = number_format($row['amount'],2,'.',',');
// ...
$paid = number_format($row['paid'],2,'.',',');
EDIT: Also, since we're talking about money, note that there is a more appropriate PHP function called [man]money_format/man for handling the formatting of the data for display purposes.