How to manipulate custom attributes of Decimal type?
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.
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
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