Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Decimal works???

Status
Not open for further replies.

dietmann

ISP
Jul 10, 2005
4
SE
Hello!
Im working in ASP and now Im began to scratch my head...=)

Say that we have an variable that is

var1 = 3
var2 = 3.65

var3 = var1 * var2 '--- Sum = 10.95

Now my Question!
How do I input this variable into MySQL in a COL whit DECIMAL (10,2)?
I only get the result 10.00 in the COL?
It seams that MySQL round every resout I get to .00 at the end.

If I make an varible hard ex.
var3 = "10.95"
that works but if I convert an numeric variable to string it doesnt?!?!?!
ex.
var4 = cstr(var3)

Pleaze help me!

// Thomas





 
I don't understand your problem. Here's what I get:
[tt]
mysql> create table t (col1 decimal(10,2));
Query OK, 0 rows affected (0.01 sec)

mysql> insert t values (10.95);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t;
+-------+
| col1 |
+-------+
| 10.95 |
+-------+
1 row in set (0.00 sec)
[/tt]
 
Thanks Tony!
I think your example is in the MySQL consol windows and there I get the the same resoult as you.
My problem is this:

I set upp an connection from an ASP side to my MySQL table and I have som variable I calculate whit and the rosult vill be in an numeric value.

Say that the varable is 10.95 and is an numeric value and I UPDATE a COL in one TABLE it rounds it to 10.00 but if I set an variable hard ex.
var1 = "10.95" (Variable presents as string)
then it works fine.

I give you my code so you understand better
and example 1 works and not the example 2.


Ex 1:
=====
<%
dbase = "Driver={MySQL ODBC 3.51 Driver}; server=******; uid=root; pwd=****; database=******"


var_discount = "10.95"


SET cn2 = Server.CreateObject("ADODB.Connection")
cn2.open dbase
SQL2 = "INSERT INTO customer_tab (discount) VALUES ('"& var_discount &"')"
cn2.execute (SQL2)
cn2.close : SET cn2 = nothing
%>



Ex 2:
=====
<%
dbase = "Driver={MySQL ODBC 3.51 Driver}; server=******; uid=root; pwd=****; database=******"

var1 = 3
var2 = 3.65

var_discount = var1 * var2


SET cn2 = Server.CreateObject("ADODB.Connection")
cn2.open dbase
SQL2 = "INSERT INTO customer_tab (discount) VALUES ('"& var_discount &"')"
cn2.execute (SQL2)
cn2.close : SET cn2 = nothing
%>


Both example work but ex2 will round 10.95 to 10.00
It dosent matter if I set the COL discounts value as FLOAT, LONG or DECIMAL whit pointers.


// Thomas








 
No its not.
When I call response.write I get the right resoults and in
MS MDB i get the rigt resoult to but thats not an option but it will show the right pointers.
Even if I give an variable a value ex

var1 = 10.95

and then use the variable in MySQL it will round it...

I cant find anyting on this problem on internet so I think I must forget someting in the syntax.
I got crasy...=)


Small problem is often the big ones...

I have tryed to find a corect syntax for it on mysql.com but I cant find anyting on it when I will calcutale whit an variabel and then use the varable in MySQL.

// Thomas



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top