There's nothing special about NumericUpDown.Value
; it's just a Decimal. Test this code and confirm that you get the same results. It might just be an issue with understanding the various arithmetic and conversions involved.
Test code:
Console.WriteLine($"Convert.ToInt32(5D Mod 10): {Convert.ToInt32(5D Mod 10)}")
Console.WriteLine($"Convert.ToInt32(5D / 10): {Convert.ToInt32(5D / 10)}")
Console.WriteLine($"Convert.ToInt32(6D Mod 10): {Convert.ToInt32(6D Mod 10)}")
Console.WriteLine($"Convert.ToInt32(6D / 10): {Convert.ToInt32(6D / 10)}")
Console.WriteLine($"Convert.ToInt32(6D) \ 10: {Convert.ToInt32(6D) \ 10}")
Console.WriteLine($"Convert.ToInt32(5D) \ 10: {Convert.ToInt32(5D) \ 10}")
Output:
Convert.ToInt32(5D Mod 10): 5
Convert.ToInt32(5D / 10): 0
Convert.ToInt32(6D Mod 10): 6
Convert.ToInt32(6D / 10): 1
Convert.ToInt32(6D) \ 10: 0
Convert.ToInt32(5D) \ 10: 0
Explanation:
5D Mod 10: No secret here. 5 Mod 10 is 5. Conversion does nothing
5D / 10: Convert.ToInt32 uses banker's rounding i.e. midpoint rounding goes to the nearest even number
6D Mod 10: Again, no secret here
6D / 10: Here it might be confusing because now you have 0.6 and it is rounded to the nearest integer. Midpoint rounding down to 0 doesn't apply because it is > the midpoint.
5D \ 10, 6D \ 10: Integer division discards decimals. Both result in 0.