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.
Printing large double values without the exponential notation?
Started by eman ahmed, Jul 25 2010 11:30 PM
3 replies to this topic
#1
Posted 25 July 2010 - 11:30 PM
|
|
|
#2
Posted 26 July 2010 - 12:03 AM
I tried to make it by using a BigDeciaml class in java
BigDecimal result =new BigDecimal (10.555551................11)
Sysout
(result )
and when I run that I found this message in console
java.lang.NoSuchMethodError: main
Exception in thread "main"
please any one who read my words
try to help me ... I'm really need a help
BigDecimal result =new BigDecimal (10.555551................11)
Sysout
(result )
and when I run that I found this message in console
java.lang.NoSuchMethodError: main
Exception in thread "main"
please any one who read my words
try to help me ... I'm really need a help
#3
Posted 26 July 2010 - 12:08 AM
About what kind of size of doubles are we talking here?
The following prints a double with 8 digits:
And for very big numbers:
The following prints a double with 8 digits:
class Something{
public Something(){}
public static void main([URL="http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky"]String[/URL][] args){
[URL="http://www.google.com/search?hl=en&q=allinurl%3Adouble+java.sun.com&btnI=I%27m%20Feeling%20Lucky"]Double[/URL] number = 0.12345678;
[URL="http://www.google.com/search?hl=en&q=allinurl%3Asystem+java.sun.com&btnI=I%27m%20Feeling%20Lucky"]System[/URL].out.format("%.8f%n", number);
}
}%n is just a newline so it acts the same as System.out.println(...);And for very big numbers:
import java.math.BigDecimal;
class Something{
public Something(){}
public static void main([URL="http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky"]String[/URL][] args){
[URL="http://www.google.com/search?hl=en&q=allinurl%3Abigdecimal+java.sun.com&btnI=I%27m%20Feeling%20Lucky"]BigDecimal[/URL] number = new [URL="http://www.google.com/search?hl=en&q=allinurl%3Abigdecimal+java.sun.com&btnI=I%27m%20Feeling%20Lucky"]BigDecimal[/URL]("1234567890123456789000.1234567890");
[URL="http://www.google.com/search?hl=en&q=allinurl%3Asystem+java.sun.com&btnI=I%27m%20Feeling%20Lucky"]System[/URL].out.println(number);
}
}
//Result: 1234567890123456789000.1234567890
Note that it's best to give a String as parameter for the BigDecimal constructor.
#4
Posted 26 July 2010 - 12:26 AM
thanks alot , I realy got it now
IT'S A very helpful site
IT'S A very helpful site


Sign In
Create Account


Back to top









