Jump to content

Printing large double values without the exponential notation?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
eman ahmed

eman ahmed

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
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.

#2
eman ahmed

eman ahmed

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
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

#3
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
About what kind of size of doubles are we talking here?

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
eman ahmed

eman ahmed

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
thanks alot , I realy got it now
IT'S A very helpful site