0

i am curious and searching basic java primitive value "double". it say double is approximately 10^308 length.

but every compile file,

error: integer number too large: 123456789101115 double a= 123456789101115;

this is my sample:

 public static void main(String []args){

    double a= 123456789101115;

    System.out.println(a);
 }

i want when it compile and running, it show 123456789101115. maybe some people say, why not use long?

actually i want to create calculation like output= 0.354 * 123456 (about 15 digit).

And one more, i want all value printout, which mean not using E.. ex: 6.6E9 but i want full ex: 6600000000 any suggest?

  • What is happening in your code: you have an int literal value 1234567890101115 first, then assign it into double, which is a process of casting int to double implicitly. – SOFe Aug 11 '16 at 04:00

1 Answers1

4

Indicate that it's a double by adding a d or D to the end, or a decimal point, or use scientific notation.

double a= 123456789101115d; // d
double a= 123456789101115D; // D
double a= 123456789101115.0; // decimal point (you can leave of the final zero)
double a= 123456789101115e0; // scientific notation

Numeric literals (numbers) in Java have a type of their own that exists regardless of the variable you assign it to. Using the above methods you can indicate that the number is a double.

Erwin Bolwidt
  • 30,799
  • 15
  • 56
  • 79
  • thanks for your answer. almost complete, but when script run, it show: 1.23456789101115E14 i want value same with my input. not using 1.23456789101115*E14* – Steven Sugiarto Wijaya Aug 11 '16 at 04:19
  • @StevenSugiartoWijaya That's scientific notation, once a number gets over a certain size it will be printed like that. But there are many other ways to format numbers in Java like `NumberFormat`. An easy way to get the output that you want is: `System.out.format("%.0f\n", a);` - this will print the number without a fraction part. – Erwin Bolwidt Aug 11 '16 at 04:52
  • thank for your help – Steven Sugiarto Wijaya Aug 12 '16 at 02:41