Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

remove leading zeros from string

843789Jun 10 2009 — edited Oct 22 2010
I am working on a report and I am having a little issue with the output.
I have several dollar amount fields that I need to format with only the decimal place. The amount fields are coming in as strings between 10-16 characters.
I could not find a way to use the currency formatter so I used substrings to break it apart and put it back together in the format I need. However I am now running into an issue with leading zeros. I can't used ReplaceAll as there is a possibility of having a 0 in the amount field.

Here is what I have done for the substrings:
int intLength = strField.length();
intDollar = intLength - 2;		
strDollar = strField.substring(1, intDollar);
strCent = strField.substring(intDollar, intLength);
System.out.println(strDollar + "." + strCent);
The original string: 0000000037049469
My output now: 00000000370494.69
Desired output: 37049469

Any suggestions on how to remove the leading zeros?

Edited by: xxwhocaresxx on Jun 10, 2009 12:11 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 19 2010
Added on Jun 10 2009
12 comments
10,326 views