0

For one calculation I need to round to 2 decimals during the calculation.

Relevant code:

count = 500;
price = 0.00077
pounds = 150,000
double value = ((350 - count) * price) * (pounds / 100);

To get the result I need, (350 - count) * price must round to 2 decimal places before doing the pounds / 100 so how might i round to 2 decimal places during a calculation?

Tiana
  • 5
  • 3

1 Answers1

0

In java you can round it some think like that

double roundOff = Math.round(a * 100.0) / 100.0;

in your case

Math.round(((350 - count) * price) * 100d) / 100d
Kamran
  • 181
  • 3
  • 13
Umer Zaman
  • 181
  • 3
  • 16