answersLogoWhite

0

Not directly. A String is an object, and a double is a primitive data type. To do the conversion you must first convert the String to a Double object (note the capital D in double), then convert that object to a double data type (lowercase d in double). Double is an object, double is a primitive data type. Here's a class that will convert a String to a double:

public class StringToDouble{

public static void main (String[] arguments) {

String s = "100.00";

double d = Double.valueOf(s.trim()).doubleValue();

System.out.println("double d = " + d);

}

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Continue Learning about Engineering

Which is the best way to convert numbers in string under java?

All of the Java number classes have a parse[type] method, like parseInt() in Integer or parseDouble() in Double that convert Strings to primitive numbers. String s = getInput(); int var = Integer.parseInt(s);


What is cdbl?

I believe it is a way to convert data in Classic ASP to double precision.


What is the algorithm to convert miles to kilometers?

Multiply miles by 1.609344 to get kilometres: double mile2km (double miles) { return miles * 1.609344; } Multiply kilometres by 0.62137119 to get miles: double km2mile (double km) { return km * 0.62137119; }


When is a double-blind study not possible?

A double blind surgery is not possible when the medical intervention a patient is getting cannot be kept from them, such as a surgery. Both the scientist and the participant in the trial know exactly what the participant is getting done in the trial.


What is type casting and what is the danger of casting from one type to another?

Type casting means that you explicitly convert from one type to another. Consider this example:int x;long y = 10;x = y;The compiler will protest, because of a possible overflow. Now, if you are confident - from a knowledge of the computer program you wrote - that there will be no overflow, you can explicitly:x = (int) y;You are telling the compiler that you know what you are doing. The danger, of course, is that you may be wrong, and there may still be an overflow.The situation is similar if you convert from double to float, or from double or float, to integer. In all of these cases, there is a loss of precision.

Related Questions

How many string on a double bass?

4 Strings.


What family does the double basses?

strings


How many strings does a double base have?

the double bass has 4 strings G string D string A string and E string.


How many strings does double guitar have?

12


Can the double bass be made with more than 4 strings?

Yes, many have 5 strings


What are the differences between a double bass and an electric double bass?

The main difference between a double bass and an electric double bass is the way they produce sound. A double bass is an acoustic instrument that produces sound through the vibration of its strings and resonance of its wooden body. An electric double bass, on the other hand, uses electronic pickups to convert the vibrations of the strings into electrical signals, which are then amplified through speakers. This allows the electric double bass to produce a louder sound and be easily heard in amplified settings, such as concerts or recordings.


How many strings does a ukulin have?

The standard ukulele will have four strings. Some instruments will double one or more of the strings. An 8 string instrument is not uncommon.


What is 4S on a DB?

4 Strings on a Double Bass


What makes the double bass so deep?

thicker strings


What instruments have fourteen strings?

no instruments have 14 strings the most strings are on the instrument is a harp. that has 47 strings


To convert strings to double?

Use the Double.parseDouble(String val) function. Remember to surround it by a try catch block to ensure that any invalid input valules to the method would not cause your application to hang out with an exeption.


How can you play the double bass?

You can play the Double Bass either arco. (which is with a bow) or pizzicato (which is plucking the strings).