By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 784 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Unexpected decimal places

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a

"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

P: n/a
"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.