I have this expression in a BPM. I need to round it to the nearest 100th. What do i need to do to accomplish this?

Thanks!

I have this expression in a BPM. I need to round it to the nearest 100th. What do i need to do to accomplish this?

Thanks!

Try using the C# Math.Round function:

Math.Round(< your expression >, 3)

The 3 is the number of decimals to round to. You can add further rules about rounding direction too.

1 Like

What if i want to round up or down?

Sorry, i just noticed you had a link about rounding direction

So the Math.Round does not entirely round to the nearest correctly, or at least according to rounding standards. For example, I have it rounding to the nearest 100th. When it rounds 2.665, it gives me 2.66. Shouldnt it be 2.67.

I tried the same number in an excel rounding formula =ROUND(2.665,2) and it gave me 2.67.

2.67 is what i am trying to accomplish.

I looked up the standards for rounding numbers. It states that a number ending in 5, 6, 7, 8, or 9 should be rounded up.

My question is why does the Math.Round not support that?

FWIW - The Floor() function always rounds â€śdownâ€ť (meaning to a lower value), and Ceiling() always rounds â€śupâ€ť

Floor(1.1) -> 1

Floor(1.999) -> 1

Ceiling(1.1) -> 2

Floor(-1.1) -> -2

Ceiling(-1.1) -> -1

Ceiling(-1.999) -> -1

See the Midpoint Rounding parameter.

```
public static decimal Round (decimal d, int decimals, MidpointRounding mode);
```

Using MidpointRounding.AwayFromZero will give you the behavior youâ€™re looking for.

Mark W.

1 Like