Solved

Convert String to Double

Posted on 2001-07-05
7
1,323 Views
Last Modified: 2008-02-26
Hi all,
 I am using JSP  and i need to convert string to double

Double.valueOf(mystring)  does not work..
 Any suggestion will be appreciated.
 
0
Comment
Question by:camasuvi
7 Comments
 
LVL 1

Expert Comment

by:gtloafer
Comment Utility
how about use the constructor Double(String)  in class Double ?

0
 

Author Comment

by:camasuvi
Comment Utility
you mean
double newValue = Double(myString)   ?
0
 
LVL 1

Expert Comment

by:gtloafer
Comment Utility
Well not quite ....rather I was thinking like this :-

Double dWrap = new Double("200");
double dVal = dWrap.doubleValue(); //this is because dWrap is an object wrapper for the primitive type double ..


regards gtloafer
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Expert Comment

by:gtloafer
Comment Utility
by the way what kind of string value are you passing ? ..Just curious thats why :-)

regards gtloafer
0
 
LVL 1

Expert Comment

by:poluru
Comment Utility
hi,
Double.valueOf(myString).doubleValue();
its working nice...i have used it many times.
why its not working ??? just try once again...
0
 
LVL 1

Accepted Solution

by:
shahnazali earned 240 total points
Comment Utility
use static method of Double
 double Double.parseDouble ( String s )

if u r not sure about your string that it contains double format number , catch NumberFormatException .

bye.

0
 

Expert Comment

by:anhphuongnn
Comment Utility

Hi,

You can try this code. is it you need?

import java.io.*;
import java.lang.*;

public class StringToDouble {
  static void main(String agrs[]) {
        Object obj = new Double("1.101");
        System.out.println("test"+obj.toString());
  }

}


Best Regard

PhuongNguyen
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now