-1

I'm using a BigDecimal variable in my application calculation. In some cases when the Bigdecimal value is 2.9922 and I save data to SQL Server 2012, I get a 2.99 record in DB. Such rounding is OK for me but sometimes I need to compare records in the DB with a new calculation and I need them to have same rounding method.

So my question is what is the rounding method in Java that will be identical to SQL server 2012 rounding method?

Is it BigDecimal.ROUND_DOWN or BigDecimal.ROUND_UP, ROUND_HALF_EVEN or which one?

Floern
  • 33,559
  • 24
  • 104
  • 119
Irakli
  • 973
  • 3
  • 19
  • 45

1 Answers1

-1

So basically it you want to deal with Scale in decimal values. For this : if you can change the decimal scale of your data column in db. for example : like if you column name is--> [value] DECIMAL(15,2)--> you can change that to [value] DECIMAL(15,5) by using alter table script.

Because BigDecimal.ROUND_DOWN or BigDecimal.ROUND_UP is satisfying the different use case.

which you can refer gere You can control the scale from java as mentioned here. Efficient BigDecimal round Up and down to two decimals

Thanks

Community
  • 1
  • 1
  • 1
    I don't need changes in DB. I need to change code to get the same rounded values as in my DB. – Irakli Aug 28 '16 at 14:04