• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Removing zeros in front of a string

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Oh sure, it's a tiny ad, but under the right circumstances, it gets bigger.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic