473,503 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing large double values without the exponential notation? - Java

2 New Member
Hi all,

I have a requirement to print large double values without the exponential notaion. The double value can be a declared variable or any calculated value within the code. In any case, I should be able to print the result without containing the exponential notation. Please help me out.
Oct 27 '07 #1
4 42711
JosAH
11,448 Recognized Expert MVP
Have a look at the DecimalFormat class; it can do the job.

kind regards,

Jos
Oct 27 '07 #2
b4ukiran
2 New Member
Hi,

I tried to use the java.text.DecimalFormat class in the following sample code:

[code]
import java.text.DecimalFormat;

public class prog2
{
public static void main(String args[])
{
String str = "1234567890123456789000.1234567890";
Double d = new Double(str);
double dd = d.doubleValue();
dd = dd + 123.0;
DecimalFormat formatter = new DecimalFormat("##0.0######");
System.out.println(formatter.format(dd));
}
}
[code]

I got the o/p as: 1234567890123456800000.0. Any more suggestions on this...
Oct 28 '07 #3
JosAH
11,448 Recognized Expert MVP
Hi,

I tried to use the java.text.DecimalFormat class in the following sample code:

Expand|Select|Wrap|Line Numbers
  1. import java.text.DecimalFormat;
  2.  
  3. public class prog2
  4. {
  5. public static void main(String args[])
  6. {
  7. String str = "1234567890123456789000.1234567890";
  8. Double d = new Double(str);
  9. double dd = d.doubleValue();
  10. dd = dd + 123.0;
  11. DecimalFormat formatter = new DecimalFormat("##0.0######");
  12. System.out.println(formatter.format(dd));
  13. }
  14. }
  15.  
I got the o/p as: 1234567890123456800000.0. Any more suggestions on this...
A double number can only store +- 15 significant digits (with a decimal dot somewhere,
that's why it's called a 'floating point number'). Your example contains way too
many significant digits, i.e. they can't all be stored in a double. The number, say,
1.23e45 would've been fine (less than 15 significant digits).

If you want numbers like that you need the BigDecimal class.

kind regards,

Jos

ps. In the Java Articles section there's an 'index' article containing a link to the
paper "What every computer scientist should know about floating point arithmetic".
It's a must read.
Oct 28 '07 #4
dbush3721
1 New Member
Hi all,

I have a requirement to print large double values without the exponential notaion. The double value can be a declared variable or any calculated value within the code. In any case, I should be able to print the result without containing the exponential notation. Please help me out.
double d = 0.0000005;
System.out.println(new DecimalFormat("#.#######################").format( d));
Oct 30 '07 #5

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

Similar topics

1
20529
by: Ryoga | last post by:
How can I print out the value of a large double in plain decimal form without the exponential notation? For example (quick code): PlainPrint.java: --------------- public class PlainPrint {...
4
10548
by: Timothy Fitz | last post by:
Why are all numberical literals in exponential notation floats? To me it is counter-intuitive for 1e3 to behave so fundamentally different from 1000. Timothy Fitz
9
6506
by: J.Sperlhofer | last post by:
Good morning, Javascript-Professionals. I'm looking for an possibility to show a (calculated) 64bit-Number without exponential notation. I don't want to see exponational notation within my...
4
21685
by: ai lian | last post by:
When I use printf to print a large double number, the result is not the same as the original input number. For example: double num=899999999999.894400; printf("%lf\n",num); The output is:...
4
5155
by: MFRASER | last post by:
How can I compare two double values and return the greater of the two values? example double doublea = 1.0; double doubleb = 2.0 double retVal = ?compare doublea and doubleb
19
2766
by: nickyeng | last post by:
i have a question from my paper, which i dont have the correct answer, so here i asking anyone who can help, provide me the appropriate answer. ----------------------------------- Write a class...
3
2110
by: ishwarbg | last post by:
Hi Everyone, I have a .Net Application, through which I am invoking a function from a legacy DLL developed in C++. My structure in C# contains some data of type double which I need to pass to to...
3
7247
ashsa
by: ashsa | last post by:
Hi everyone, I am trying to display a numeric value fetched from an sql server table which is stored in the exponential notation. For eg, 0.08 is getting stored in the table as...
2
11874
by: Felipe Oliveira Gutierrez | last post by:
I hava a number too large and when i plus it with another number the result is showed in exponential notation on my screen. how to not leave the javascript do that? Thanks
0
7086
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
7280
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
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
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,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.