%dw 2.0
output application/json
---
{
noRounding: 123.456 as String,
roundUp: 123.456 as String {format: "0.00"},
roundEvenUp: 123.455 as String {format: "0.00"},
roundDown: 123.454 as String {format: "0.00"}
}
{
"noRounding": "123.456",
"roundUp": "123.46",
"roundEvenUp": "123.46",
"roundDown": "123.45"
}
You can select a different round mode by adding the roundMode attribute, and selecting one of the available modes from the Java class java.math.RoundingMode by name.
| Mode | Description |
| CEILING | Rounding mode to round towards positive infinity. |
| DOWN | Rounding mode to round towards zero. |
| FLOOR | Rounding mode to round towards negative infinity. |
| HALF_DOWN | Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down. |
| HALF_EVEN | Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor. |
| HALF_UP | Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up. |
| UNNECESSARY | Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary. |
| UP | Rounding mode to round away from zero. |
%dw 2.0
output application/json
---
{
noRounding: 123.456 as String,
roundDown: 123.456 as String {format: "0.00", roundMode:"DOWN"},
roundHalfDown: 123.455 as String {format: "0.00", roundMode:"HALF_DOWN"},
roundCeiling: 123.454 as String {format: "0.00", roundMode:"CEILING"}
}
{
"noRounding": "123.456",
"roundDown": "123.45",
"roundHalfDown": "123.45",
"roundCeiling": "123.46"
}
As you can see the results are completely different with the same numbers, because of the different rounding options used.%dw 2.0
output application/json
fun roundDown(n,p) = do {
var power = 10 pow p
---
if (n>0) floor(n * power)/power
else ceil(n * power)/power
}
---
{
noRounding: 123.456,
roundDown: roundDown(123.456,2)
}
Output
{
"noRounding": 123.456,
"roundDown": 123.45
}
001115993

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.