Satyajit Bhadange wrote:I don't want it for printing purpose.I want to use the calculated value
In first case value which i want is 845
and in second case value i need is 8178
Currently in my code i am calculating both values
using Math.max(x,y) i am selecting the value.
You can't be sure that will always work. You are likely at some point to get values like
You've been told both what the problem and solution are. If you need that degree of precision, you can't use floats/doubles.
you're told to use a hammer.
You the reply with "well, I can use this really, really big wrench".
If BigDecimal is the right tool, why don't you want to use it?
I used BigDecimal in my code but still facing same problem.
Below Code is using BigDecimal
Below code i am using Math.max(double,float)
The problem statement is from Codeforces Problem Statement - Codeforces
Try it for yourself.
campbell@computer:~/java> java BigDecimalDemo 1.0
bd1 equals bd2: true
bd1 = 1.000000000000000000000000000000, bd2 = 1.000000000000000000000000000000
campbell@computerj:~/java> java BigDecimalDemo 0.1
bd1 equals bd2: . . .