-3

Lets say ItemImpl takes in "int ItemId, String name, BigDecimal price"

How do I put a BigDecimal number in the input of this?

Item item = new ItemImpl(5, "Hockey Stick", BigDecimal(1.5));

Also what's the point of BigDecimal?

  • this post can help: https://stackoverflow.com/questions/3413448/double-vs-bigdecimal – Ibo Nov 03 '17 at 03:25

2 Answers2

3
Item item = new ItemImpl(5, "Hockey Stick", new BigDecimal("1.5"));

Best practice is to use a String due to precision issues

And this link I think answers pretty much everything you might want to know: http://www.opentaps.org/docs/index.php/How_to_Use_Java_BigDecimal:_A_Tutorial

information_interchange
  • 2,026
  • 4
  • 24
  • 43
0

The point of BigDecimal is that it offers better precision than double and it also solves round-off errors.

Judger
  • 208
  • 1
  • 4