aspose file tools*
The moose likes Beginning Java and the fly likes parsing string to Integer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "parsing string to Integer" Watch "parsing string to Integer" New topic
Author

parsing string to Integer

Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

i am having problem to convert a string into integer . here is the code.

please tell me what is the problem??


Good luck!!
A small leak can sink a Gigantic ship.>
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

can i get the answer please!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
Are you seriously becoming impatient after just 14 minutes? PatienceIsAVirtue

Next time you post about a problem, be sure to include any exception you're getting, and any other salient details. Just posting a piece of code and asking "what is the problem" is unlikely to elicit helpful responses, especially if quickly followed by something with an exclamation mark.

So: What is happening if you run this code? Why do you think that is? Note that -despite the class name- there is no casting going on here: Integer.parseInt expects an integer, and nothing else.


Ping & DNS - my free Android networking tools app
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

okay Dittmer.
its My fault!
Exception in thread "main" java.lang.NumberFormatException: For input string: "1600.00"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:456)
at java.lang.Integer.parseInt(Integer.java:497)
at intCast.main(intCast.java:5)

I am getting this exception.
Amit Vinod Dali
Ranch Hand

Joined: Apr 14, 2010
Posts: 42
For tutorial on Converting Strings to Numbers Click here
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

UlF mentioned already. i.e,
String value = "1600.00"; this value is not an Integer . instead, use Float or Double
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

It means that 1600.00 can not be parsed to integer?
only integer values can be parsed!
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

thank you all!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Raza Mohd wrote:It means that 1600.00 can not be parsed to integer?
only integer values can be parsed!

It *can*, but not by passing it to something that expects a string representation of an integer.
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

yeah I split the string to get the integer value!
and pass it for the parsing.
Is there any chance to parse it without truncating it to integer?
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
With Integer class? No.
As said before you can use Float or Double classes

Look at this:



You can do the same thing with Float class



Bye,
Nicola
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: parsing string to Integer