?
Solved

casting string to a double

Posted on 2003-03-10
7
Medium Priority
?
320 Views
Last Modified: 2010-03-31
I want cast a String into a double
I would also like the code to turn the string 8808 (for example) into an integer
0
Comment
Question by:obirdman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 8109086
double d = Double.parseDouble("1.6");
int n = Integer.parseInt("8808");
0
 
LVL 2

Expert Comment

by:antonsigur
ID: 8110459
Here is a solution with error handling, you should always do that if you are parsing for example user input.. you never know if your user won't just type "abcd" where you wanted "1234"

        String a = "123.4";
        String b = "2394";
       
        double d = 0;
        int i = 0;

        try {
            d = Double.parseDouble(a);
            i = Integer.parseInt(b);
        } catch (NumberFormatException e) {
            e.printStackTrace();  
        }
0
 
LVL 92

Expert Comment

by:objects
ID: 8115022
> Here is a solution with error handling

Any code should have error handling.
I really don't think it is necessary to show it when giving examples.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Expert Comment

by:antonsigur
ID: 8115187
Yes, you are right, but obirdman just doesn't seem to know java very well, so I'm just showing him how that works! I think hi should give you the points, because you answered before me!
0
 

Expert Comment

by:CleanupPing
ID: 9058797
obirdman:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 35

Expert Comment

by:girionis
ID: 9700526
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points to objects

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question