Page 1 of 1

Number formatting

Posted: Sun Aug 07, 2005 5:05 am
by summitweb
Hello:

I have four columns:
item = xx
unit price = 55.00
quantity = 30
extended price = 1,650.00 (unit price * quantity)

The subtotal (which adds the total column) should appear as 1,650.00. Instead, the number I'm getting is 1.00.

The subtotal number prints correctly up to 999.99. As soon as it reaches a 1,000 and higher as in my case 1,650.00, my number prints 1.00 leaving out the 650 part.

I'm not sure why. I hope someone can help.

Here's what I did with my code:

First, I set my $subtotal = 0;

Second, for my total price I'm using the following calculation:
$extprice = number_format($price * $qty, 2);

Third, I wrote a calculation which adds the extended price to a subtotal before taxes:
$subtotal = $extprice + $subtotal;

Finally, I want to print the $total which appears as such:

Code: Select all

<tr>
<td colspan="3" align="right">Subtotal:</td>
<td align="right"> <?php echo number_format($subtotal, 2); ?></td>


Can someone help me out?

Thanks.

Posted: Sun Aug 07, 2005 7:25 am
by feyd
a comma is not legal numerics.. you need to adjust your insertion code so you don't store the visual representation of the subtotal but the actual value..

Posted: Sun Aug 07, 2005 8:36 am
by summitweb
Hi,

Thanks for the reply. I discovered the solution.