Results 1 to 4 of 4
Thread: Integer parseInt(str) question
- 03-07-2011, 09:46 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
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
- 03-07-2011, 09:53 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Check out string formatting.
- 03-07-2011, 10:01 PM #3
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Java Code:System.out.printf("Dollar: %d Cent: %02d ",dollar, cent);
- 03-07-2011, 10:10 PM #4
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Working with Integer parseInt(String)
By Rocketz in forum New To JavaReplies: 3Last Post: 02-27-2011, 07:31 AM -
Integer.parseInt() error
By niteangell21 in forum New To JavaReplies: 4Last Post: 02-06-2011, 05:36 AM -
[SOLVED] Integer.parseInt() problem
By eggmanpete in forum New To JavaReplies: 18Last Post: 02-15-2009, 04:25 PM -
Integer.parseInt?
By Exhonour in forum New To JavaReplies: 4Last Post: 01-20-2009, 02:31 AM -
Problem with Integer.parseInt()
By Hevonen in forum New To JavaReplies: 2Last Post: 12-14-2008, 03:41 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks