Integer parseInt(str) question
parseInt question:
I have a string - "00000000030001".
This is a dollar value from a file. So I need to store last 2 digits as CENTS and rest of the digits as DOLLAR.
Integer.parseInt works fine for dollar as 000000000300 but it returns 1 for cents instead of 01.
How can I have the code return 01 for cents value.
Here is code snippet:
String str = "00000000030001";
int startPos = 0;
int endPos = 12;
dollar = Integer.parseInt(str.substring(startPos, endPos));
startPos = 13;
endPos = 15;
cent = Integer.parseInt(str.substring(startPos, endPos));
System.out.println("Dollar: " + dollar + " Cent: " + cent);
output:
Dollar: 300 Cent: 1
I need output as Dollar: 300 Cent: 01