I have a code like :
def a = 2111 - 1112
//which calculates a as 999.
But in the above result i need a to be as 0999, i.e i need the leading zeros in the a. How i can do this?
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.
Seems like there should be a much Groovy-er solution, but this the best I could come up with:
I doubt you want to actually change the behavior of the “-” operator, but if you do, I think it’d be better if you changed String’s metaClass.subtract instead and used “2111” – “1112”