File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Explain me . Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Explain me ." Watch "Explain me ." New topic

Explain me .

Ashok Pradhan
Ranch Hand

Joined: Dec 17, 2007
Posts: 180

When i run this program i got the answer 1.0E-5,i know that 1.0E-5=0.00001,but how could i get the result 0.00001
Amit Y Desai
Ranch Hand

Joined: Dec 06, 2007
Posts: 35
hi Ashok,

i faced with same problem previously but could not find any solution.
If you are having double value starting with "0." followed by three 0's then resulting format in sysout would not be in form 0.0000XXXX but would be in format XXE+-XXX
Amit Y Desai
Ranch Hand

Joined: Dec 06, 2007
Posts: 35
Infact there is solution

Try to use the method DecimalFormat.format(double), inherited from the class NumberFormat.

DecimalFormat myFormatter = new DecimalFormat(pattern);
String output = myFormatter.format(value);
System.out.println(value + " " + pattern + " " + output);

pattern can be for example "###.###" or "###,###.###"

You should also read the Java Documentation pages on DecimalFormat class.

go to sun api here
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
The solution above is appropriate. Basically, the default way of printing floating point numbers (double and float) is only intended for debugging, not nicely-formatted output. You should use something like a DecimalFormat to present floating-point numbers to the user.

Be aware, however, that floating-point arithmetic is not exact. This is nothing to do with Java; it's the same in all languages. Floating-point should be used where you need to store numbers with a wide range of value in a smallish, fixed amount of memory and fast computation and where approximation is acceptable.

Where you need total accuracy, you should not use floating-point. You should either use integers (int, long etc.), scaled appropriately (e.g. use an integer number of thousandths), or use the BigDecimal class. BigDecimal can represent quite a big range (not as big as floating-point), but uses much more memory than floating-point and is also slower to compute.

Currency (money) calculations are the most common example of where floating-point is inappropriate. Never use floating-point for currency. Usually, the best thing to do is to use integers, representing all amounts as the smallest unit in the currency (e.g. cents, pence).

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
also you could use,%20java.lang.String,%20java.lang.Object...)

Bill Shirley - bshirley -
if (Posts < 30) JavaRanchFAQ);
I agree. Here's the link:
subject: Explain me .
jQuery in Action, 3rd edition