Skip to content

Conformance Examples 0.1.0 — Transforms: transform-round

round-half-rounds-up

A positive half rounds away from zero via {{ n | round }}.

Template

{{ n | round }}

Context

{
    "n": 2.5
}

Output

3

round-negative-half-rounds-away

A negative half rounds away from zero.

Template

{{ n | round }}

Context

{
    "n": -2.5
}

Output

-3

round-below-half-rounds-down

A value below the half rounds down.

Template

{{ n | round }}

Context

{
    "n": 2.4
}

Output

2

round-integer-unchanged

round of an integer is unchanged.

Template

{{ n | round }}

Context

{
    "n": 7
}

Output

7

round-one-decimal-place

round with a places argument keeps that many decimals via {{ n | round: 1 }}.

Template

{{ n | round: 1 }}

Context

{
    "n": 1.46
}

Output

1.5

round-two-decimal-places

round with two decimal places.

Template

{{ n | round: 2 }}

Context

{
    "n": 0.246
}

Output

0.25

round-non-numeric-input-is-null

A non-numeric input is a soft failure, so round yields null.

Template

{{ n | round }}

Context

{
    "n": "x"
}

Output

null

round-negative-places-is-null

A negative places argument is a soft failure, so round yields null.

Template

{{ n | round: -1 }}

Context

{
    "n": 5
}

Output

null

round-non-integer-places-is-null

A non-integer places argument is a soft failure, so round yields null.

Template

{{ n | round: "x" }}

Context

{
    "n": 5
}

Output

null

Source fixture: transforms/transform-round.json