473,386 Members | 1,924 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.

Unexpected decimal places

Any ideas why this statement:

mBalanceChange = Double.Parse(strCurrentBalance,
Globalization.NumberStyles.AllowThousands Or
Globalization.NumberStyles.AllowDecimalPoint) - mBalanceDouble

would leave me with a double containing over 10 decimal places when
strCurrentBalance was a string containing a double with two decimal places
and mBalanceDouble contained only two decimal places to begin with?

I know I can format mBalanceChange to contain only two decimal places but
I'm curious how it would end up with extra decimal places in the first place
in this case.

Thanks.
Jun 27 '08 #1
3 1967
Regardless of actual figures ? Floating point values are *approched* values.
You may have run in such a case. For financial application using the Decimal
type is likely better...

--
Patrice

"David" <da*********@yoowhoo.coma écrit dans le message de news:
m4******************************@comcast.com...
Any ideas why this statement:

mBalanceChange = Double.Parse(strCurrentBalance,
Globalization.NumberStyles.AllowThousands Or
Globalization.NumberStyles.AllowDecimalPoint) - mBalanceDouble

would leave me with a double containing over 10 decimal places when
strCurrentBalance was a string containing a double with two decimal places
and mBalanceDouble contained only two decimal places to begin with?

I know I can format mBalanceChange to contain only two decimal places but
I'm curious how it would end up with extra decimal places in the first
place in this case.

Thanks.


Jun 27 '08 #2

"David" <da*********@yoowhoo.comwrote in message
news:m4******************************@comcast.com. ..
Any ideas why this statement:

mBalanceChange = Double.Parse(strCurrentBalance,
Globalization.NumberStyles.AllowThousands Or
Globalization.NumberStyles.AllowDecimalPoint) - mBalanceDouble

would leave me with a double containing over 10 decimal places when
strCurrentBalance was a string containing a double with two decimal places
and mBalanceDouble contained only two decimal places to begin with?

I know I can format mBalanceChange to contain only two decimal places but
I'm curious how it would end up with extra decimal places in the first
place in this case.
double data type is a 'close approximation' of the numbers.
For accurate results, use the Decimal data type - as Patrice pointed out.

Jun 27 '08 #3
"David" <da*********@yoowhoo.comschrieb:
mBalanceChange = Double.Parse(strCurrentBalance,
Globalization.NumberStyles.AllowThousands Or
Globalization.NumberStyles.AllowDecimalPoint) - mBalanceDouble

would leave me with a double containing over 10 decimal places when
strCurrentBalance was a string containing a double with two decimal places
and mBalanceDouble contained only two decimal places to begin with?

I know I can format mBalanceChange to contain only two decimal places but
I'm curious how it would end up with extra decimal places in the first
place in this case.
(Complete) Tutorial to Understand IEEE Floating-Point Errors
<URL:http://support.microsoft.com/?scid=kb;EN-US;42980>

IEEE Standard 754 Floating Point Numbers
<URL:http://steve.hollasch.net/cgindex/coding/ieeefloat.html>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jun 27 '08 #4

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

Similar topics

17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
3
by: Brent Bortnick | last post by:
Does anyone know how to find out the number of decimal places a number has. I need this info so that i can round to 3 decimal places if the number has 3 decimal places or to 2 decimal places if...
2
by: Carl G | last post by:
I am storing a 0.000 a System.Decimal in a DataRow. On retrieval the value is only 0 without the three decimal places. It looks like the Get property returns System.Decimal.Zero, but why???? I...
4
by: italia | last post by:
I changed the Fieldsize Property from text to Long Integer and Decimal Places = 6. I had decimals in the original field. But after the transfer, the digits after the decimals are gone. Now...
8
by: nick | last post by:
printf("%lf",3.25); the result is 3.25000 i want the answer correct to 3 decimal places What should i do? thanks!
3
by: mohaaron | last post by:
Hello All, Does anyone know of a way to test a decimal for the number of places it has before and after the decimal? I need to do something like this. decimal value1 = 172.45; // If value1...
19
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm...
2
by: hunslair | last post by:
This is a really basic question. I am taking a teach yourself beginners course on Access 2003 and have run into a road block on one practice. In a select query, I have created a simple calculation...
5
by: =?Utf-8?B?anVzdGluc2FyYWNlbm8=?= | last post by:
I'm using .net 2.0 and am having a problem adding doubles: double x = 63881.97 + 34297.98; The result of this addition in Visual Studio is 98179.950000000012 This is obviously the incorrect...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.