It's all about the answers!

Ask a question

How to manipulate custom attributes of Decimal type?


Luiz Almeida (23015489) | asked Oct 21 '14, 9:34 a.m.
Hi all,
Here is my doubt:

I have a workitem that contains custom attributes of Decimal type. These attributes are calculated and saved by a follow up plugin. In my code, this attributes are manipulated as BigDecimal.

One of the attributes is a financial value, but is showed in interface in the following format "1.834,4785"

I want to consider only two digits for cents, for example: 1.834,47.

So, how must I format the BigDecimal to save value in this format? Or how can I format the output field to show in this format? Can I format the output in a query result?

Thanks for help.

Accepted answer


permanent link
Ryan Ruscett (1.0k413) | answered Oct 23 '14, 2:50 p.m.
setScale(int newScale, RoundingMode roundingMode)
Returns a  BigDecimal  whose scale is the specified value, and whose unscaled value is determined by multiplying or dividing this  BigDecimal 's unscaled value by the appropriate power of ten to maintain its overall value.
You would need to use the int for scale and set it to 2. Then you can use the roundingMode to determine HALF_DOWN HALF_EVEN etc. I put a rounding mode link below
http://docs.oracle.com/javase/7/docs/api/java/math/RoundingMode.html

Luiz Almeida selected this answer as the correct answer

Your answer


Register or to post your answer.