0

I have a problem with assigning one big decimal value to another

I am trying such as creating one temp big decimal and add 0 to another big decimal

BigDecimal temp = new BigDecimal(0);
dropStartValue =  temp.add(newCounterValue);

However, I only want simply do the operation below on big decimals:

dropStartValue = newCounterValue
soField
  • 2,536
  • 9
  • 36
  • 44

2 Answers2

4

You haven't specified the type of either dropStartValue or newCounterValue. If they're both BigDecimals, then this should be fine:

dropStartValue = newCounterValue;

Note that although that's just making both variables refer to the same object, it's safe because BigDecimal itself is immutable.

If that's not working for you, please give details of what problems you're seeing (exceptions? compile-time errors?).

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

Assuming this is Java ans newCounterValue is an integer type or a box thereof, dropStartValue = new BigDecimal(newCounterValue); should do what you want.

Romain
  • 12,679
  • 3
  • 41
  • 54
  • I thought that originally - but BigDecimal.add doesn't take ints etc, so I suspect newCounterValue is another BigDecimal... – Jon Skeet Dec 07 '09 at 12:49
  • @Jon: Sure it does: http://java.sun.com/javase/6/docs/api/java/math/BigDecimal.html#BigDecimal(int) – T.J. Crowder Dec 07 '09 at 12:52