why percentage returns 0 when rate = 0.085 for example ?
int percentage = (int)rate*100;
The cast operation is applied before the multiplication. Try:
int percentage = (int)(rate*100);
Edit: Here's the C# guide on order of operator evaluation.
It returns 0 because of order of operations. rate
is cast as an integer prior to multiplying.
You need an extra set of parentheses to make this work.
int percentage = (int)(rate*100);
Try:
int percentage = (int)(rate * 100);
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