473,320 Members | 2,052 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,320 software developers and data experts.

Losing Accuracy in reading numbers

AGP
I thought i had this down but i think i am missing something. i read in a
series of strings in CSV format that are actually numbers. i do something
like

Dim gVal as Double
Dim sData as String = "77.05788457660967"

gVal = Double.Parse(gArrCoords(0),
Globalization.NumberFormatInfo.InvariantInfo)
Debug.printline(gVal)

and this is what i get printed
77.057884576609666

This one seems to be small but i thought the double was supposed to hold the
exact number. I think the conversion has to do with the accuarcy built into
the format type but I cant figure out how to convert the exact number.
Suppose this was a scientific app that required extreme accuarcy in reading
the source data. How would i read it or assign it differently?

tia

AGP


Aug 31 '08 #1
4 1090
AGP,

Simple search on Internet about accuracy and doubles. This is a dead horse.

Cor
"AGP" <si**********@softhome.netschreef in bericht
news:5p*****************@flpi150.ffdc.sbc.com...
>I thought i had this down but i think i am missing something. i read in a
series of strings in CSV format that are actually numbers. i do something
like

Dim gVal as Double
Dim sData as String = "77.05788457660967"

gVal = Double.Parse(gArrCoords(0),
Globalization.NumberFormatInfo.InvariantInfo)
Debug.printline(gVal)

and this is what i get printed
77.057884576609666

This one seems to be small but i thought the double was supposed to hold
the
exact number. I think the conversion has to do with the accuarcy built
into
the format type but I cant figure out how to convert the exact number.
Suppose this was a scientific app that required extreme accuarcy in
reading
the source data. How would i read it or assign it differently?

tia

AGP

Aug 31 '08 #2
AGP
Gotcha. I've been doing that search for the last hour or so. Will do some
more reading and learning but so far I've learned that the double can hold
15 significant digits of accuarcy. I think I was mistakingly assuming the
range of the double would take care of my numbers but that is not the case.

In my case the documentation for the source data only states that the value
is consisting of floating point value.Looks like one solution is changing my
type to Decimal but i have to weight the performnce hit.

AGP

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:7D**********************************@microsof t.com...
AGP,

Simple search on Internet about accuracy and doubles. This is a dead
horse.

Cor
"AGP" <si**********@softhome.netschreef in bericht
news:5p*****************@flpi150.ffdc.sbc.com...
>>I thought i had this down but i think i am missing something. i read in a
series of strings in CSV format that are actually numbers. i do something
like

Dim gVal as Double
Dim sData as String = "77.05788457660967"

gVal = Double.Parse(gArrCoords(0),
Globalization.NumberFormatInfo.InvariantInfo)
Debug.printline(gVal)

and this is what i get printed
77.057884576609666

This one seems to be small but i thought the double was supposed to hold
the
exact number. I think the conversion has to do with the accuarcy built
into
the format type but I cant figure out how to convert the exact number.
Suppose this was a scientific app that required extreme accuarcy in
reading
the source data. How would i read it or assign it differently?

tia

AGP


Aug 31 '08 #3

Dim sData As String = "77.05788457660967"

Dim GVal As Decimal = Decimal.Parse(sData,
Globalization.NumberFormatInfo.InvariantInfo)

Debug.WriteLine(GVal)



HTH

Michel


"AGP" <si**********@softhome.netschreef in bericht
news:5p*****************@flpi150.ffdc.sbc.com...
>I thought i had this down but i think i am missing something. i read in a
series of strings in CSV format that are actually numbers. i do something
like

Dim gVal as Double
Dim sData as String = "77.05788457660967"

gVal = Double.Parse(gArrCoords(0),
Globalization.NumberFormatInfo.InvariantInfo)
Debug.printline(gVal)

and this is what i get printed
77.057884576609666

This one seems to be small but i thought the double was supposed to hold
the
exact number. I think the conversion has to do with the accuarcy built
into
the format type but I cant figure out how to convert the exact number.
Suppose this was a scientific app that required extreme accuarcy in
reading
the source data. How would i read it or assign it differently?

tia

AGP


Aug 31 '08 #4
AGP wrote:
Gotcha. I've been doing that search for the last hour or so. Will do
some more reading and learning but so far I've learned that the
double can hold 15 significant digits of accuarcy. I think I was
mistakingly assuming the range of the double would take care of my
numbers but that is not the case.
In my case the documentation for the source data only states that the
value is consisting of floating point value.Looks like one solution
is changing my type to Decimal but i have to weight the performnce
hit.
I bet a nickel that the source data is coming from an app where the original
values were Doubles in the first place. On export to CSV, a value like
77.057884576609666 might very well be written to a file as "77.05788457660967."

Unless you find evidence that the source data had better than double floating
point (64 bit) precision, I would read the data back into doubles; that will
most closely reconstruct the original data.
Aug 31 '08 #5

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

Similar topics

3
by: aurora | last post by:
I have a parser I need to optimize. It has some disk IO and a lot of looping over characters. I used the hotspot profiler to gain insight on optimization options. The methods show up on on the...
11
by: Michael Lang | last post by:
You'd think that the advantage to extra decimal places in a data type is better accuracy. Well think again. Look at this method and test results: ...
5
by: Mr Fish | last post by:
Is it possible for me to record floats in a std::stringstream with 100% accuracy? If so how? Here's a little prog that demonstrates how the default ss loses accuracy ...
6
by: Thomas Lumley | last post by:
What does the standard guarantee about the accuracy of eg the trigonometric functions? There is obviously an implementation-dependent upper bound on the accuracy, since the answer is stored in a...
86
by: Michael Adams | last post by:
I don't know if you have noticed, but it seems like Microsoft is losing interest in C#, and putting their energy into Visual Basic.NET instead. For instance, online chats by language since July...
5
by: fbwhite | last post by:
I know this issue has been brought up many times, but I have tried many of the solutions to no avail. I wanted to give my specific case to see if someone could be of any help. We are using the...
2
by: RRoma | last post by:
Does anybody know how I can import lists of numbers from Excel into Access without losing the preceeding Zeros??? The field must have a total of 10 digits.... Is this a function of how its saved in...
5
by: Sensei | last post by:
Hi again! I am trying to figure a simple example of a program that shows the accuracy differences between float and double types. In particular I'm searching for an operation that works on...
16
by: Hatzigiannakis Nikos | last post by:
In the following code main() { double x; for (x=0.0;x<=1;x=x+0.05) { printf("x=%6.3f \n",x); } }
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.