I'm loosing values off the string?????

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
shab620
Forum Commoner
Posts: 48
Joined: Tue Jan 18, 2005 7:50 pm

I'm loosing values off the string?????

Post by shab620 »

Hye

I've got a simple calculations which i'm doing. the first part of the query works fine, this is looking up the price of the item and then bringing it back. i then use my variable which has been filled by the form and extract the quantity. I then multiply the two togeother and insert the new value into the orders table.
the problem is that if the figure comes to say 2.20 i'm loosing the '0' and when the insert happens it comes as 2.2.
How can i overcome this problem????
The table which the look up is being performed on has a property of varchar for the price.

Can anyone help????

Code is as follows for the calculation

Code: Select all

$result = mysql_query ("SELECT Item_Description, Item_Price from item where item_id = '$item_id'",$connect) 
or die ("There was an error in the query");
while ($row = mysql_fetch_assoc($result))
{
$item_description=$row['Item_Description'];
$price=$row['Item_Price'];
$total = $price * $quantity;
}
$query = ("INSERT INTO emp_order VALUES ('','$item_description','$quantity','$comments','$user_name','$total','Uncomplete')");
Any help appreciated

Shab
:D :D
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

What is the problem of losing the 0 at the end, the numbers are technically identical?
shab620
Forum Commoner
Posts: 48
Joined: Tue Jan 18, 2005 7:50 pm

Post by shab620 »

Hello

I understand your point but its a price field and when reading it back it will be just a little awkward

If theres a solution then i would like to implement it

Shab

:D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you could leave it and just format the value when you display it in php.. http://php.net/printf
shab620
Forum Commoner
Posts: 48
Joined: Tue Jan 18, 2005 7:50 pm

Post by shab620 »

Hello Feyd

That makes more sense, will do it like that

thanks

shab

:D :D
Post Reply