aspose file tools*
The moose likes Java in General and the fly likes Removing zeros in front of a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Removing zeros in front of a string" Watch "Removing zeros in front of a string" New topic
Author

Removing zeros in front of a string

igwe kalu kalu ogba
Ranch Hand

Joined: Feb 03, 2005
Posts: 133
Hi, I have a question:
I'm retrieving values from a database and getting a number like 23 outputted as 00000024, It varies.
My question is, how can I remove the first x zeros from a number. Can any of the numberformat tools help? Thanks.
Cathy Song
Ranch Hand

Joined: Jul 01, 2003
Posts: 92
Something like this perhaps?

class a{
public static void main (String args[]){

String test = "0000024";
Integer i = new Integer (test);
System.out.println (i);
int num = i.intValue();
System.out.println (num);
}
}
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

I guess he means only to suppress some of the Zeros:

000000042
....00042 (x=4).

printf or regexp could help:



[ August 04, 2005: Message edited by: Stefan Wagner ]

[ August 04, 2005: Message edited by: Stefan Wagner ]
[ August 04, 2005: Message edited by: Stefan Wagner ]

http://home.arcor.de/hirnstrom/bewerbung
Dharmesh Gangani
Ranch Hand

Joined: Feb 20, 2004
Posts: 30
You can get the data truncated from the database query as well. this removes a few lines of code.

Eg. If you want to truncate the value from the database to say 2 leading zeros' (0024), u can use the database query as -

select to_char(<col_name>, '0099') from <table_name>

The tow 0's indicate the number of leading zero's required & the 9's indicate the fixed number of digits required.

Hope this solves your purpose.
In case you have any further queries, please feel free to ask.


-=-=-=-=-=-=-=-=-=-<br />Thanks & Regards,<br />Dharmesh G.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Removing zeros in front of a string
 
Similar Threads
String to long datatype conversion problem
left filled zero
XSLT format-number() issue
Can you convert HEX to Binary w.o. lossing leading zeros?
Sequence Problem