my doubles get not rounded as expected. Simple example:
int b = 23;
double DurchflussAktBit = 99.5;
double bDurchfluss = 0;
bDurchfluss = DurchflussAktBit * Convert.ToDouble(b) / (double)60;
Math.Round(bDurchfluss, 2);
I get the value 38.141666666666666 for bDurchfluss even after the rounding, I expect the value 38.14. Also tried Math.Round((decimal)bDurchfluss, 2); but gives me the same value.
Where is the error in my code?
Math.Round returns the rounded number - it does not update the number you passed it.
You need to take the return value and assign it to your variable:
bDurchfluss = DurchflussAktBit * Convert.ToDouble(b) / (double)60;
bDurchfluss = Math.Round(bDurchfluss, 2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With