I get gpnString as a String and I have to parse it to an int.
I was using Integer.parseInt(gpnString) but gpnString contains leading zeros and they get removed with Integer.parseInt().
The gpnString has allways the length of 8 so I tried to add so many 0 as needed but the int detects it as NULL so it does not add the number 0. This is my Code:
int parseToInt(String gpnString) {
int gpn = Integer.parseInt(gpnString);
for (int addZero = 8 - String.valueOf(gpn).length(); addZero != 0; addZero--) {
gpn = 0 + gpn;
}
return gpn;
}
/*
Input : gpnString = "00012345"
Output: 12345
*/
I have looked this up on Stackoverflow but I only found an answer like this:
String gpn = String.format("%08d" , gpnSring);
I have tried it but you get a String so I would have to parse it again and this would lead to the exact same Problem as before.
Edit:
I heard an Integer or int can not have leading zeros...
I use the gpn for personal identification in a Database. Would the best Idea be to edit the grafical output so it just looks like it has the 0? Or is there a better way to solve this?
01is1. There's no way to store leading zeroes in anintorInteger.010is actually equal to 8.