here's a snipit of code that i have , . what do i need to add to make this work
weight is a double while data[2] is read from a txt file ( yes its a double in the txt file )
weight = data[2];
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
here's a snipit of code that i have , . what do i need to add to make this work
weight is a double while data[2] is read from a txt file ( yes its a double in the txt file )
weight = data[2];
Programming: the art that fights back
Primitive conversion from String to double can be done using the static method on the Double wrapper class. There are two of them which will parse the string into a either a Double wrapper object or a double primitive.
String stringDouble = "123.456"; Double wrapperDouble = Double.valueOf(stringDouble); // This gives you a return type of Double wrapper object double primitiveDouble = Double.parseDouble(stringDouble); // This give you a return type of the double primitive
Also note that if you try to parse a string into any number but the string has invalid characters such as "123.4g56" the static method will throw a NumberFormatException.
// JsonException in thread "main" java.lang.NumberFormatException: For input string: "123.4g56"
wolfgar (October 13th, 2009)
thanks , that helps alot
Programming: the art that fights back