473,718 Members | 2,060 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 42742
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.Decim alFormat class in the following sample code:

[code]
import java.text.Decim alFormat;

public class prog2
{
public static void main(String args[])
{
String str = "12345678901234 56789000.123456 7890";
Double d = new Double(str);
double dd = d.doubleValue() ;
dd = dd + 123.0;
DecimalFormat formatter = new DecimalFormat(" ##0.0######");
System.out.prin tln(formatter.f ormat(dd));
}
}
[code]

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

I tried to use the java.text.Decim alFormat 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: 123456789012345 6800000.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.prin tln(new DecimalFormat(" #.############# ##########").fo rmat(d));
Oct 30 '07 #5

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

Similar topics

1
20556
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 { public static void main(String args) { double aValue = 123456789.1234; System.out.println(aValue); }
4
10555
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
6545
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 binary numbers. To demonstrate my problem, try this code: ---- var binNumber = Math.pow(2,61);
4
21697
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: 899999999999.894409 Could anyone tell me what the problem is? How can I get the right output?
4
5164
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
2780
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 called Point that holds two double values representing the x and y coordinates of a point on graph. Provide the following: 1. A suitable default constructor that can also take one or both of the 2 values as arguments. Default values should be 0. ...
3
2129
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 the DLL to get some results back from it. My Structure In C# looks like this: public struct InputPurchaseOrder { public System.String poJobName;
3
7280
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 8.0000000000000002E-2. This causes the xslt function format-number() to fail. I use it as <xsl:value-of select='format-number(8.0000000000000002E-2, "###,###.00")' /> The message says that This name may not contain the '#' character: -->#<--##,###.00...
2
11925
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
8827
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9358
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9208
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9053
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7991
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4481
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4743
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3182
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2559
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.