Manually converting a string to double..
How to convert String to Double without using parseDouble?
Collapse
X
-
Hi deBiidpOL and welcome to bytes.com!
The String class has several useful functions, the best for this problem is probably charAt(int). This will return the character represented at a certain position in the string, so for example [code=java]"123.456".charA t(1)[/url] would be a '2' (as it starts counting with 0).
As soon as you have a character, you'll have to somehow convert it into part of the Double. You have 3 different situations I can think of that might occur:- A sign, namely '-' or, possibly, '+'. This will decide whether the Double is positive or negative.
- A digit. If your character represents a digit you can handle that.
- A decimal point. If you find one of these, all characters right of this should be added to the Double accordingly.
Short of solving it for you, that's all I can think of right now. Hope it helps. :-)
Comment