I understand this:
35%10 returns 5
but, why does 000000035%10 return 9?
Ruby does the same thing. I checked with irb.
Should I strip the 0s that are padding the number? What is the java function to do that?
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.
When you put the leading zeros followed by octal digits (from
0to7), you’re creating an octal literal. And since000000035in octal is29in decimal, its remainder with10is9.UPDATE
If you have your “octal literal” in a string, simply use
Integer.parseIntand you’ll get it parsed as a decimal.