I have difficulties calculating percentage of a double value. I wrote the code below but it always show “0”. What can be the problem?
double percent = 80; //Percent
double toCalc = 1/1000000; //1 uAmper
MessageBox.Show((toCalc * (percent / 100F)).ToString());
Thanks.
1/1000000needs to be performed as a floating point division. I’d write it like this:The way you wrote it, the division will be performed as an integer division, and then promoted to a floating point value. The integer division results in 0 which explains what you are seeing.