469,631 Members | 1,579 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

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 1816
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Brent Bortnick | last post: by
8 posts views Thread by nick | last post: by
3 posts views Thread by mohaaron | last post: by
5 posts views Thread by =?Utf-8?B?anVzdGluc2FyYWNlbm8=?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.