473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Small Math Errors when Converting Text to Single

TC
I am getting small math errors when I use a query to convert a column's
data type from Text to Single. I am using a calculated column with the
following expression.

HighSchoolGPA: IIf(IsNull([GPA]),Null,CSng([GPA]))

When GPA = "3.10", HighSchoolGPA := 3.09999990463257, not 3.1. For this
particular application, the difference between 3.09999990463257 and 3.1
is unacceptable.

A couple of notes: When I evaluate
IIf(IsNull("3.10"),Null,CSng("3.10")) in the immediate window, I get
the correct result of 3.1. Also, the table containing GPA is linked via
ODBC to a SQL Server database.

I can easily workaround the problem by using the Round() function, but
I'd prefer to understand why I'm getting the problem in the first
place. Can anyone offer advice?
-TC

Oct 28 '06 #1
1 2059
TC wrote:
I am getting small math errors when I use a query to convert a column's
data type from Text to Single.

http://msdn2.microsoft.com/en-us/lib...em.single.aspx

the page includes:

"Remember that a floating-point number can only approximate a decimal
number, and that the precision of a floating-point number determines
how accurately that number approximates a decimal number. By default, a
Single value contains only 7 decimal digits of precision, although a
maximum of 9 digits is maintained internally. The precision of a
floating-point number has several consequences:

Two floating-point numbers that appear equal for a particular precision
might not compare equal because their least significant digits are
different.

A mathematical or comparison operation that uses a floating-point
number might not yield the same result if a decimal number is used
because the floating-point number might not exactly approximate the
decimal number.

A value might not roundtrip if a floating-point number is involved. A
value is said to roundtrip if an operation converts an original
floating-point number to another form, an inverse operation transforms
the converted form back to a floating-point number, and the final
floating-point number is equal to the original floating-point number.
The roundtrip might fail because one or more least significant digits
are lost or changed in a conversion."

Oct 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Tom | last post by:
Has anyone ever seen a IComparer for floats the returns magnitude. i.e. instead of returning -1, it would return -5. To let you know HOW different the two numbers are. obviously for int it is a -...
7
by: Wernfried Schwenkner | last post by:
I've found the discussion about Math.Log and the error with Math.Log(8,2) on Google. Unfortunatly the full thread isn't on my news server, so I can't reply. The problem doesn't only depend...
16
by: lawrence k | last post by:
I've a file upload script on my site. I just now used it to upload a small text document (10k). Everything worked fine. Then I tried to upload a 5.3 meg Quicktime video. Didn't work. I've...
11
by: Sambo | last post by:
I have the following module: ------------------------------- import math def ac_add_a_ph( amp1, ph1, amp2, ph2 ): amp3 = 0.0 ph3 = 0.0 ac1 = ( 0, 0j ) ac2 = ( 0, 0j )
16
by: Bill Nguyen | last post by:
I'm running into a very weird problem regarding subtraction. Subtraction behaves as if it's an addition in the below sub txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####0") ...
2
by: astrogirl77 | last post by:
Hi, I'm new to Python and am hoping to find help with coding a Python script, applet. I code in an old version of Visual Basic 4.0, I have a simple app that is about 3 and a half pages of code...
1
by: astrogirl77 | last post by:
I'm new to C++ and am hoping to find help with coding a simple C program, am wanting to obtain code and functioning exe's. I code in an old version of Visual Basic 4.0, I have a simple app that...
17
by: Lenni | last post by:
Hi, I'm currently writing a web application for bicycle wheel builders that calculate the spoke length for all sorts of variations of hubs and rims. I have translated the formula from an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.