Number formatting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
summitweb
Forum Commoner
Posts: 27
Joined: Thu Jun 30, 2005 4:28 am
Location: Atlanta, Georgia

Number formatting

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
summitweb
Forum Commoner
Posts: 27
Joined: Thu Jun 30, 2005 4:28 am
Location: Atlanta, Georgia

Post by summitweb »

Hi,

Thanks for the reply. I discovered the solution.
Post Reply