Reputation: 21
I want to compute square of 1000000.I am using java which data type should I use,I tried using primitive double and even Big decimal... Is there any data type or class which I can Use??
Upvotes: 0
Views: 744
Reputation: 7242
1,000,000 * 1,000,000 is one trillion (1e12).
long
can hold up to 9,223,372,036,854,775,807 which is much larger than one trillion and so is suitable for your calculation.
'int' can hold up to 2,147,483,647 which is not large enough for your calculation, and so is not suitable.
double
and float
are floating point and do not seem necessary for your use case at this time (unless you are actually trying to take the square root?).
Upvotes: 2