So, question:
How would I “re-add” all leading zero(es) in a String of length 9 (that is truncated when being converted from a Long)?
More details:
In the “front-end” (API), the String value sent in is of length 9, : e.g. “000000000”, “000000001”, “000000010”
Request body:
{
someObjects: [
someObject1: {
Id: “000000000”;
],
someObject2: {
Id: “000000001”
},
someObject3: {
Id: “000000010”
}
}
The corresponding java class is:
class SomeObject {
Long id;
}
In the handler method:
public void someRequestHandlerMethod(List<SomeObject> someObjects) {
for(SomeObject someObject : someObjects) {
Long Id = someObject.getId();
LOGGER.info(“Id is: ”+Id);
}
}
What is happening, is if a number starts with zero(es), when it is converted to a Long, all the zero(es) in front of the remaining number are getting truncated. e.g. “000000000” becomes “0” “000000001” becomes “1” “000000010” becomes “10” and so forth.
So it prints out:
Id is: 0 (instead of Id is: 000000000).
Id is: 1 (instead of Id is: 000000001).
Id is: 10 (instead of Id is: 000000010).
Question: How would I retain the zero(es) or “re-add” them using String manipulation, so that it prints out like:
“000000000” is printed out as “000000000” and not as “0”
“000000001” is printed out as “000000001” and not as “1”
“000000010” is printed out as “000000010” and not as “10”.
Basically, retaining or “re-adding” all leading zero(es) in a number String of lenth 9?
Any help would be greatly appreciated!
thank you so much!