-1

I try to do some caculation to get tax value. That work but it's display to much number.

 Price it's a BigDecimal     

 BigDecimal tps = price().multiply(tpsRate());
 tps.setScale(2, BigDecimal.ROUND_UP);

 BigDecimal tvq = price().multiply(tvqRate());
 tvq.setScale(2, BigDecimal.ROUND_UP);

 BigDecimal tps = report.getPrice().multiply(report.getTpsRate());
 tps.setScale(2, BigDecimal.ROUND_UP);

 BigDecimal tvq = report.getPrice().multiply(report.getTvqRate());
 tvq.setScale(2, BigDecimal.ROUND_UP);

If the price is 200.00 tvq it's calculated to 14.0000 tps it's calculated to 18.0000

price().add(tvq).add(tps)

total 232.0000

I want to get 14.00, 18.00 and 232.00

robert gagnon
  • 311
  • 1
  • 5
  • 14

1 Answers1

2

BigDecimal, like String, are immutable. This means you can't change the value, only return a new value.

tvq.setScale(2, BigDecimal.ROUND_UP);

This calculates a BigDecimal with two decimal places, but you are discarding it. I suspect you wanted to keep the value returned.

tvq = tvq.setScale(2, BigDecimal.ROUND_UP);
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130