Hello everyone How can I get the difference between a number and the next number divisible by 10 in c#?
Example.
15 should give 5. (20-15 =5)
21 should give 9. (30-21=9)
30 should give 0. (30-30=0)
Sorry for my english.
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Mod won’t work, that will give you the opposite of what you want. 21%10=1 not 9 like you want. What you should do is 10-(num%10). This will get you much closer. The only result that will be wrong in this case is 30, which will give a result of 10.
so:
This will give you the correct result everytime, although a bit cumbersome.