0

I want the help to produce the result of below calculation as 1.12 but the result is coming up 1.0 double k=(112)/100; System.out.println(k);

2 Answers2

1

You are doing Integer division causing it to lose the precision:

Replace

double k=(112)/100;

with

double k=(112.0)/100;

VHS
  • 9,534
  • 3
  • 19
  • 43
0

double k-=((double)112/100) worked for me as suggested by agni

when we do division like (112/100) JVM gives int as an o/p, you are storing that 'int' in 'double' so JVM adds '.0' to the o/p causing loss of precision. so, here you have to tell the JVM to give o/p without any loss. for that reason we have to mention like `double k = (double)112/100; which is similar to "typecasting".