Click here to Skip to main content
15,894,410 members
Home / Discussions / C#
   

C#

 
QuestionWhat is the difference - Convert.Int32() --- Int32.Parse() --- (int) Pin
dataminers4-Sep-08 3:53
dataminers4-Sep-08 3:53 
AnswerRe: What is the difference - Convert.Int32() --- Int32.Parse() --- (int) Pin
Ravi Bhavnani4-Sep-08 3:56
professionalRavi Bhavnani4-Sep-08 3:56 
AnswerRe: What is the difference - Convert.Int32() --- Int32.Parse() --- (int) Pin
DaveyM694-Sep-08 4:09
professionalDaveyM694-Sep-08 4:09 
AnswerRe: What is the difference - Convert.Int32() --- Int32.Parse() --- (int) Pin
Guffa4-Sep-08 6:53
Guffa4-Sep-08 6:53 
QuestionPause and Resume facility in a downloader application using C# Pin
Student Developer4-Sep-08 3:32
Student Developer4-Sep-08 3:32 
AnswerRe: Pause and Resume facility in a downloader application using C# Pin
Ravi Bhavnani4-Sep-08 3:54
professionalRavi Bhavnani4-Sep-08 3:54 
QuestionSecure Data Exchange Between WinfForm app and Web Service Pin
#realJSOP4-Sep-08 3:22
mve#realJSOP4-Sep-08 3:22 
AnswerRe: Secure Data Exchange Between WinfForm app and Web Service Pin
Manas Bhardwaj4-Sep-08 3:27
professionalManas Bhardwaj4-Sep-08 3:27 
AnswerRe: Secure Data Exchange Between WinfForm app and Web Service Pin
Ravi Bhavnani4-Sep-08 4:02
professionalRavi Bhavnani4-Sep-08 4:02 
GeneralRe: Secure Data Exchange Between WinfForm app and Web Service Pin
#realJSOP4-Sep-08 4:11
mve#realJSOP4-Sep-08 4:11 
AnswerRe: Secure Data Exchange Between WinfForm app and Web Service Pin
led mike4-Sep-08 5:29
led mike4-Sep-08 5:29 
AnswerRe: Secure Data Exchange Between WinfForm app and Web Service Pin
leppie4-Sep-08 9:05
leppie4-Sep-08 9:05 
GeneralRe: Secure Data Exchange Between WinfForm app and Web Service Pin
#realJSOP5-Sep-08 0:20
mve#realJSOP5-Sep-08 0:20 
GeneralRe: Secure Data Exchange Between WinfForm app and Web Service Pin
leppie5-Sep-08 3:50
leppie5-Sep-08 3:50 
Questiondouble Pin
RugbyLeague4-Sep-08 2:20
RugbyLeague4-Sep-08 2:20 
AnswerRe: double [modified] Pin
c24234-Sep-08 2:51
c24234-Sep-08 2:51 
I would guess that at least one of these numbers cant be expressed exactly in binary, leading to a loss of precision

A simplified example:
0.3
could be approximated as 1/4 + 1/8 (0.01 + 0.001)
= .25 + 0.125
which is 0.375 i.e. a loss of precision

Obviously the .Net framework will have a more complex floating point mechanism to allow more possible numbers, but hopefully you get my point that some floating point numbers are hard to express in binary without some loss of information.

To solve the problem you could perhaps multiply all your floating point numbers by something, add them together and then divide again later - this sometimes will give a more precise answer

for example:
0.3 + 0.3
Approximated to 0.375 + 0.375 = .75 rather then .6
But:
((0.3 * 10) + (0.3 * 10)) / 10
=
(3 + 3) / 10
= 6 / 10 = .6
Converted into bin: 0.11
(which again is a loss of precision, but less so)

Again as a disclaimer, the maths I am trying to use to explain is over simplified and .Net is more complex then this!

Hopefully that helps,
Chris

[Edit: to elaborate on my point here is some test code I just wrote:
int i = 0;
i += 963;
i += 29;
i += 654;
i += 386;
i += 526;
double x = (double)i / 10000;


However I also tried the example given in the OP, and got the correct answer with no precision loss - different OS or version of .Net perhaps...

]

modified on Thursday, September 4, 2008 9:00 AM

AnswerRe: double Pin
RugbyLeague4-Sep-08 2:52
RugbyLeague4-Sep-08 2:52 
AnswerRe: double Pin
Mbah Dhaim4-Sep-08 2:53
Mbah Dhaim4-Sep-08 2:53 
AnswerRe: double Pin
DaveyM694-Sep-08 3:11
professionalDaveyM694-Sep-08 3:11 
GeneralRe: double [modified] Pin
#realJSOP4-Sep-08 3:27
mve#realJSOP4-Sep-08 3:27 
GeneralRe: double Pin
Dan Neely4-Sep-08 4:32
Dan Neely4-Sep-08 4:32 
QuestionPanel screencapture is black in invisible part of panel Pin
joost.versteegen4-Sep-08 2:05
joost.versteegen4-Sep-08 2:05 
AnswerRe: Panel screencapture is black in invisible part of panel Pin
leppie4-Sep-08 9:02
leppie4-Sep-08 9:02 
GeneralRe: Panel screencapture is black in invisible part of panel Pin
joost.versteegen4-Sep-08 23:11
joost.versteegen4-Sep-08 23:11 
GeneralRe: Panel screencapture is black in invisible part of panel Pin
leppie4-Sep-08 23:47
leppie4-Sep-08 23:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.