# Convert numeric String into Integer (Java)

Discussion in 'Java' started by Azmie, Dec 28, 2003.

1. ### AzmieGuest

Anyone can help me to solve this problem.
I want to convert numeric string = "000000075" into Integer value = 75

What is the best approach?

Azmie, Dec 28, 2003

2. ### SudsyGuest

Azmie wrote:
> Anyone can help me to solve this problem.
> I want to convert numeric string = "000000075" into Integer value = 75
>
> What is the best approach?
>

Integer.parseInt( string );

Sudsy, Dec 28, 2003

3. ### VisionSetGuest

"Azmie" <> wrote in message
news:...
> Anyone can help me to solve this problem.
> I want to convert numeric string = "000000075" into Integer value = 75
>
> What is the best approach?

All you need to do is browse java.lang.Integer in the API docs for about 30
seconds to arrive at the answer...

int i = Integer.parseInt("00000075");

or if you'd like that wrapped

Integer i = Integer.valueOf("00000075");

--
Mike W

VisionSet, Dec 28, 2003
4. ### Thomas SchodtGuest

(Azmie) wrote in
news::

> I want to convert numeric string = "000000075" into Integer value = 75

I assume you mean int, rather than Integer

String s = "000000075";
int n = Integer.parseInt(s);

PS.
Basic questions like this really belong in c.l.j.help

Thomas Schodt, Dec 28, 2003
5. ### Dan AckroydGuest

String szSomeString = "0000075";

nSomeNumber = Integer.getInteger( szSomeString ) ;

danack

"Azmie" <> wrote in message
news:...
> Anyone can help me to solve this problem.
> I want to convert numeric string = "000000075" into Integer value = 75
>
> What is the best approach?
>

Dan Ackroyd, Dec 28, 2003
6. ### VisionSetGuest

"Dan Ackroyd" <> wrote in message
news:bsn55m\$2ej\$...
>
> String szSomeString = "0000075";
>
> nSomeNumber = Integer.getInteger( szSomeString ) ;
>
>
> danack

No, getInteger(String s) returns an Integer object,
or throws an exception if s is not parsable

--
Mike W

VisionSet, Dec 28, 2003
7. ### Roedy GreenGuest

Roedy Green, Dec 28, 2003
8. ### Andrew ThompsonGuest

"VisionSet" <> wrote in message
news:C6EHb.12029\$...
> "Azmie" <> wrote in message
> news:...
> > Anyone can help me to solve this problem.
> > I want to convert numeric string = "000000075" into Integer value = 75

....
> or if you'd like that wrapped

Yes please, pretty paper, with a bow! ;-)

Andrew Thompson, Dec 29, 2003
9. ### nosGuest

"Roedy Green" <> wrote in
message news:...
> On 28 Dec 2003 08:43:22 -0800, (Azmie) wrote or quoted
> :
>
> >I want to convert numeric string = "000000075" into Integer value = 75
> >

>
> see http://mindprod.com/converter.html
>
> --
> Canadian Mind Products, Roedy Green.
> Coaching, problem solving, economical contract programming.
> See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

if(s.equals("000000075")) i=new Integer(75);

nos, Dec 29, 2003
10. ### Andrew ThompsonGuest

"nos" <> wrote in message
newstLHb.64476\$VB2.125226@attbi_s51...
> > On 28 Dec 2003 08:43:22 -0800, (Azmie) wrote or quoted

....
> > >I want to convert numeric string = "000000075" into Integer value = 75

...
> if(s.equals("000000075")) i=new Integer(75);

.....
else if (s.equals("00000075")) i=new Integer(75);
else if (s.equals("000075")) i=new Integer(75);
else if (s.equals("00075")) i=new Integer(75);
else if (s.equals("0075")) i=new Integer(75);
else if (s.equals("075")) i=new Integer(75);
else if (s.equals("75")) i=new Integer(75);
else if (s.equals("00000076")) i=new Integer(76);
......

Andrew Thompson, Dec 29, 2003
11. ### akGuest

> ...
> > > >I want to convert numeric string = "000000075" into Integer value =

75
> ..
> > if(s.equals("000000075")) i=new Integer(75);

> ....
> else if (s.equals("00000075")) i=new Integer(75);
> else if (s.equals("000075")) i=new Integer(75);
> else if (s.equals("00075")) i=new Integer(75);
> else if (s.equals("0075")) i=new Integer(75);
> else if (s.equals("075")) i=new Integer(75);
> else if (s.equals("75")) i=new Integer(75);
> else if (s.equals("00000076")) i=new Integer(76);

lol, the biggest if else construct!!!

____________

ak, Dec 29, 2003
12. ### Michiel KonstapelGuest

>> String szSomeString = "0000075";
>>
>> nSomeNumber = Integer.getInteger( szSomeString ) ;
>>
>>
>> danack

>
> No, getInteger(String s) returns an Integer object,
> or throws an exception if s is not parsable
>

Nope, getInteger(String s) uses s as the name of a system property and
creates an Integer (or null) from its value. Does anyone actually use these
methods, like Integer.getInteger() and Boolean.getBoolean()?
Michiel

Michiel Konstapel, Dec 29, 2003
13. ### AzmieGuest

Thanks to everyone. the simple way i do this is using parseint function.
Happy new year...

Azmie, Dec 30, 2003