I need to convert Object o to Double. Is the correct way to convert it to String first?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t cast an object to a
Doubleif the object is not a Double.Check out the API.
particularly note
valueOf(double d);and
valueOf(String s);Those methods give you a way of getting a
Doubleinstance from a String or double primitive. (Also not the constructors; read the documentation to see how they work) The object you are trying to convert naturally has to give you something that can be transformed into a double.Finally, keep in mind that
Doubleinstances are immutable — once created you can’t change them.