Contact Us 1-800-596-4880

decimalRound

decimalRound(n: Number, ctx: OperationContext = DECIMAL_128_CONTEXT)

Returns the argument number with rounding specified by the operation context.

Example

This example shows how decimalRound behaves with different operation contexts.

Source

%dw 2.0
import * from dw::util::Math
output application/json
---
{
  "decimalRound123456": decimalRound(123.456, {precision: 4, roundingMode: "HALF_UP"}),
  "decimalRound25HalfUp": decimalRound(2.5, {precision: 1, roundingMode: "HALF_UP"}),
  "decimalRound25HalfEven": decimalRound(2.5, {precision: 1, roundingMode: "HALF_EVEN"})
}

Output

{
   "decimalRound123456": 123.5,
   "decimalRound25HalfUp": 3,
   "decimalRound25HalfEven": 2
}