473,388 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

conversion of string to double

Ive got a string s="11316500.00"
i want to convert it to double and get dTot = 11016500.00

How do i do this? please help
Mar 23 '07 #1
11 7998
horace1
1,510 Expert 1GB
Ive got a string s="11316500.00"
i want to convert it to double and get dTot = 11016500.00

How do i do this? please help
have a look at parseDouble()
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html#parseDouble(java.lang.String)
Mar 23 '07 #2
Ive got a string s="11316500.00"
i want to convert it to double and get dTot = 11016500.00

How do i do this? please help
There are many ways to kill a cat. It depends on which method suites u and what you want to achieve.

I will do it by an anonymous instantiation of a Double wrapper class, - because all wrapper classes have a constructor that takes in a String argument to create the wrapper instance - with your input string. Then use the no-arg unboxing method of that Double wrapper class -(doubleValue()) -to get the primitive value of type double. all this is done in one line. Here it is -:
Expand|Select|Wrap|Line Numbers
  1. dTot = new Double("11316500.00").doubleValue();
  2.  
Mar 23 '07 #3
have a look at parseDouble()
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html#parseDouble(java.lang.String)

i did not get a solution from the above link.....
please help
Mar 23 '07 #4
r035198x
13,262 8TB
i did not get a solution from the above link.....
please help
Do you mean that you tried the parseDouble method and it didn't work?
The link is pretty clear to me.
Mar 23 '07 #5
Ive got a string s="11316500.00"
i want to convert it to double and get dTot = 11016500.00

How do i do this? please help
Hi
this might help you.

double dTot=Double.parseDouble(s);

Varun
Mar 23 '07 #6
Hi
this might help you.

double dTot=Double.parseDouble(s);

Varun
when i do parseDouble i get 1.138606E7 not as 113860650
Mar 23 '07 #7
when i do parseDouble i get 1.138606E7 not as 113860650
suppose if i get a double value as 1.138606E7 , then how do i convert it to double value 11386065.00
Mar 23 '07 #8
suppose if i get a double value as 1.138606E7 , then how do i convert it to double value 11386065.00
look at the DecimalFormat references of the java.text package on the net. THat can be used to format the output. Something like-:

Expand|Select|Wrap|Line Numbers
  1. //where doIt is a double
  2. new java.text.DecimalFormat("#,##0.00")).format(doIt)
  3.  
Mar 23 '07 #9
horace1
1,510 Expert 1GB
suppose if i get a double value as 1.138606E7 , then how do i convert it to double value 11386065.00
by default System.out.println() prints large double values in exponential format - you can now format the output using System.out.printf() which is similar to the C printf() function
try
Expand|Select|Wrap|Line Numbers
  1.  String s="113860650";
  2.  double x=Double.parseDouble(s);
  3.  System.out.println(x);
  4.  System.out.printf("%f", x);
which prints
1.1386065E8
113860650.000000
Mar 23 '07 #10
by default System.out.println() prints large double values in exponential format - you can now format the output using System.out.printf() which is similar to the C printf() function
try
Expand|Select|Wrap|Line Numbers
  1.  String s="113860650";
  2.  double x=Double.parseDouble(s);
  3.  System.out.println(x);
  4.  System.out.printf("%f", x);
which prints
1.1386065E8
113860650.000000
that is handy horace1. Cool!!!!!!!
Mar 23 '07 #11
r035198x
13,262 8TB
suppose if i get a double value as 1.138606E7 , then how do i convert it to double value 11386065.00
Technically that is not converting it to a double value.
1.138606E7 is the double value. What you probably want is convert it to a string in which case the suggestions you've got will work.
Mar 23 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jazper | last post by:
hi can anybody explain that to me: i did the following: - 1. input of char 244 ("ô") into string - 2. convert to getbytes - 3. convert back to string char 244 changed to char 63 ("?")...
2
by: flybird | last post by:
how can can I read the string( doubule characters:kanji or chinanese character ) from a text file using C#.
1
by: Felix | last post by:
I am a bit confused as to why conversion from float/double to int is handled in c# in the way that it is. It differs from my implementation of C and C++ in a suprising way (to me). Here is a...
8
by: Oenone | last post by:
Is it possible to create an object which can have methods and properties, but which can also be treated as a string? I'm trying to create a wrapper around the IIS Request.Form object which...
2
by: chauhan.alok | last post by:
hi I am a beginner to vc++. I am opening a file("c:\Mydoc.doc") and reading data from it and after that i just want to write data of 1.2 MB part from first file("c:\Mydoc.doc") to New...
2
by: Arvid Requate | last post by:
Hello, I'd like to understand why the following code does not compile. It looks like a strangeness in connection with overload resolution for the <complex> header: The conversion operator...
5
oll3i
by: oll3i | last post by:
public class Cennik { private static Cennik instance = null; Map<String,Double> cennik = new HashMap<String,Double> (); private Cennik() { // prywatny konstruktor } public...
4
by: Max80 | last post by:
Hi Everyone, I have a double value (e.g. 2.00) which I would like to convert to string. Simply returning the value using the .ToString() method trims the 0s after the decimal...
1
by: krishna81m | last post by:
I am a newbie and have been trying to understand conversion from double to int and then back to int using the following code was posted on the c++ google group. Could someone help me out with...
1
by: amollokhande1 | last post by:
Hi All, I want to build an application that will convert the english characters into other languages like Chinees, Japanies etc using VB.net. I am looking for use of Double byte character set for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.