449,025 Members | 960 Online
Need help? Post your question and get tips & solutions from a community of 449,025 IT Pros & Developers. It's quick & easy.

# convert number string to number

 P: 7 how can i convert number string to number?(without using parsint) Jan 5 '11 #1
9 Replies

 Expert Mod 10K+ P: 12,408 Why can't you use parseInt? Jan 5 '11 #2

 Expert 100+ P: 938 A fair and valid question - this is exactly what parseInt is for. Check out this link: http://www.exampledepot.com/egs/java...onvertNum.html for examples on all the parse... functions. Jan 6 '11 #3

 P: 7 Hi Korea, If str is a number string then u can convert to number by int i=Integer.valueOf(str) Thanks, Prasant Jan 6 '11 #4

 P: 7 thx u for your help but i am java starter and my teacher sayed me to write code to convert string to number for example : 0ne million there hundred ===== 1.003.000 Jan 6 '11 #5

 Expert 100+ P: 938 As far as I'm aware there are no standard classes to achieve this as valueOf() takes a string like "1003000" and will convert it to an int. I'm not sure how to parse a proper numeric name (One million and three thousand) into an int. I would be thinking of a series of loops and checks to parse the string. Interested to hear if anyone else has any ideas on it as it could be an interesting little project. Jan 7 '11 #6

 Expert Mod 10K+ P: 12,408 It all depends on how many different ways you want to be able to capture how someone is going to spell something. Are they going to say thirtyfour, thirty-four, or thirty four. And then there's the question of typos. If you're going to need to capture different ways of typing the same thing, I'm thinking regular expressions. But, seeing as how this is a school assignment, they probably just need to follow a strict format. In which case they can just code specifically for that format. Jan 7 '11 #7

 Expert 100+ P: 938 RegExp could work. Coding for specifics would be my recommendation and then implementing some sort of exception handling. You could develop your own illegalformatexception class. Jan 7 '11 #8