473,405 Members | 2,272 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,405 software developers and data experts.

Converting Double to String

75
Hi All,
I need to convert a Double value to String.The requirement is as follows

Double do=1234567890123456.12;
String str=Double.toString(do);

when i execute it i am getting the values in exponential format.
which is like: 1.234567890123456E15

But i need the values to be converted exactly into String.I cannot use BigDecimals due to the requirements.

The code is as follows.

public class test1 {
public static void main(String[] args) {
double aDouble = 1234567890123456.12;
String aString=Double.toString(aDouble);
System.out.println(aString1);}
}

Please help me in this regard as it would be help ful for my project completion.

Thanks in Advance!!!
Oct 3 '07 #1
3 3781
r035198x
13,262 8TB
Hi All,
I need to convert a Double value to String.The requirement is as follows

Double do=1234567890123456.12;
String str=Double.toString(do);

when i execute it i am getting the values in exponential format.
which is like: 1.234567890123456E15

But i need the values to be converted exactly into String.I cannot use BigDecimals due to the requirements.

The code is as follows.

public class test1 {
public static void main(String[] args) {
double aDouble = 1234567890123456.12;
String aString=Double.toString(aDouble);
System.out.println(aString1);}
}

Please help me in this regard as it would be help ful for my project completion.

Thanks in Advance!!!
Have a look at what the DecimalFormat can do for you.
Oct 3 '07 #2
JosAH
11,448 Expert 8TB
A double uses 53 bits for its mantissa (or 'significand'). That implies that the
order of magnitude between the leftmost (most significant) and rightmost bit
(least significant) is 2^53 == 9.007199254740992E15 so at most 16 (a bit less)
significant decimal digits can be stored in a double. Your value (which also is
a denormalized value) tries to use more digits than that and you can never store
it without a bit of loss of precision (those rightmost digits).

kind regards,

Jos
Oct 3 '07 #3
Ozzi
4
It is not possible to receive such a BigDecimal in a Double.
The easiest thing you can do is:

BigDecimal myBigDecimal = new BigDecimal("1234567890123456.12");
System.out.println(myBigDecimal.toPlainString());
Oct 4 '07 #4

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

Similar topics

5
by: matt melton | last post by:
Hi there, I am trying to write a method that accepts an array of any primitive type and will return the same array without copying memory as an array of bytes. ie. I'd like to be able to do...
4
by: Cyde Weys | last post by:
I'm currently working on converting a simulator program from Visual Basic 6.0 to Visual C++ .NET. I've figured out most of the stuff, but there's still one thing I haven't gotten to and I've never...
4
by: rainmaker1234 | last post by:
Its very simple in VC++. In the followeing code I have declared a String, and a double than I am taking the string and converting it into Double. getch() at the end is only to pause the screen so...
5
by: shang | last post by:
Hi! I am trying to find a function that converts a string into a double or a long double number. I found atod() but I don't know which library I have to include to use it. Could someone help me? ...
12
by: Frederik Vanderhaeghe | last post by:
Hi, I have a problem converting text to a double. Why doesn't the code work: If Not (txtdocbedrag.Text = "") Then Select Case ddlBedrag.SelectedIndex Case 0 Case 1
5
by: SMichal | last post by:
Hi, how can I parse string "? 20.000" to double ?
10
by: Ron | last post by:
I want to calculate the surface area of a sphere from an inputed radius with option strict on. I guess I am not converting something correctly. Here is what I am doing: I have a textbox...
3
by: nvx | last post by:
Hi, I'm looking for a simple way to convert a Double to a String exactly the .ToString() does, except these two differences: - the number of decimals is given (rounding is applied if necessary),...
25
by: Blasting Cap | last post by:
I keep getting errors that pop up when I am trying to convert an application from dotnet framework 1.1 to framework 2.0. The old project was saved in sourcesafe from Visual Studio 2003, and I have...
7
by: ma740988 | last post by:
Consider the equation (flight dynamics stuff): Yaw (Degrees) = Azimuth Angle(Radians) * 180 (Degrees) / 3.1415926535897932384626433832795 (Radians) There's a valid reason to use single...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.