This simple calculation is returning zero, I can't figure it out:
decimal share = (18 / 58) * 100;
Dividing any number by itself will always result in the number one. Any number multiplied by zero equals zero. The rule we're learning about today might sound like the opposite of that last one: You can't divide any number by zero.
In Python 2, 25/100 is zero when performing an integer divison. since the result is less than 1 . You can "fix" this by adding from __future__ import division to your script. This will always perform a float division when using the / operator and use // for integer division.
In the C Programming Language, the div function divides numerator by denominator. Based on that division calculation, the div function returns a structure containing two members - quotient and remainder.
The symbol used to represent division is the forward slash (/). If you want to divide one number by another, you'll need to place the forward slash character between them. Using the same values for a and b as in the example above, check out how to divide two numbers in C# below: Console.
You are working with integers here. Try using decimals for all the numbers in your calculation.
decimal share = (18m / 58m) * 100m;
18 / 58
is an integer division, which results in 0.
If you want decimal division, you need to use decimal literals:
decimal share = (18m / 58m) * 100m;
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