I have a input dialog box where the user is required to enter a number(any number eg: 11323.9983). I need to take that number and add it to another number. How do i convert the string into any number? eg float, int, long...
I did find a numbers() method but i can't seem to find any syntax examples. any suggestions welcome.
Simply providing an answer like that deprives the original poster of the opportunity to learn for herself, to find her way round the API documentation etc.
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
So we prefer not to give straight answers like that; please don't be annoyed with me for deleting it.
Originally posted by Maja Gralewska:
I looked in the api but it only shows me methods that can convert a string to an int or float or.... unless I'm completely missing it(then please tell me), I'm looking for one method that will convert the string to the necessary number no matter what the user inserts.
What classes have you looked at?
Inside Integer, what static methods have you found? Does one of those look like it can return an int? Now once you've found that one, Float, Double, Byte, Short and Long have similar methods.
Beware "." is a meta-character which must be escaped. You can find the format for floating point number in the "grammar" in the Java Language Specification.
remember,in java,nothing is passed by
,so you can never expect that reply will come back modified.
moreover you are using
reply is a string and '+' operator is used by strings to concatenate