Title: decimal places problem with ODBC/ASP?
I didn't see an answer to your question yet, so here goes.
 
This is the fundamental problem with using floating point numbers in the database.  If you don't want these minor rounding discrepancies, then use fixed point numbers, e.g. DECIMAL, data types for the columns in question instead of floating point numbers.  For example, if there can only be up to two digits before and after the decimal place, your column would be of type DECIMAL (5,2).  Then, the values will always remain exactly as the users entered them.

--
Chris Ingram
Synchrologic, Inc.
Email: [EMAIL PROTECTED]

-----Original Message-----
From: Bill Seitz [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, May 08, 2001 12:46 PM
To: [EMAIL PROTECTED]
Subject: decimal places problem with ODBC/ASP?

Win2K, MsSql2K, IIS5, etc.

I have HTML forms which do a POST to Python/ASP pages which call my .py class which uses the "standard" ODBC module to insert a record into MsSQL.

This particular app is an online timesheet app: enter timecharges to jobs, administrator reviews/approves/exports, etc.

The UnitsCharged field is a float. The HTML form limits entries to 3 chars, entries are typically "1.2" or "0.7" or "4", etc. Everything goes in fine, when you view the results via ASP they look fine.

But when you do a direct (SQL Query Analyzer) query into the table you see values sometimes like 0.69999999999999996, etc. (while others work out just fine).

I figure this is probably a binary/decimal conversion problem, right? But it makes me nervous to have nasty data in there, I'm afraid it will bite me in the ass sometime (someone will see an ugly value someplace, and it will undermine the credibility of the system). Is there anything I can do about this? Change the field type in SQL? Use a different SQL module? Or do I just hold my nose and live with it?

Reply via email to