Page 1 of 1

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

Posted: Sat Mar 26, 2005 2:27 pm
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

Posted: Sat Mar 26, 2005 2:35 pm
by John Cartwright
What is the problem of losing the 0 at the end, the numbers are technically identical?

Posted: Sat Mar 26, 2005 2:36 pm
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

Posted: Sat Mar 26, 2005 2:38 pm
by feyd
you could leave it and just format the value when you display it in php.. http://php.net/printf

Posted: Sat Mar 26, 2005 3:34 pm
by shab620
Hello Feyd

That makes more sense, will do it like that

thanks

shab

:D :D