0

I have a value of €1850.50. I want a calculation to round this to €1851 My formula is

ToNumber(Round(Replace([Item Data.LHC Part Anaes Rate 2019 (No Rounding)],"€",""))) 

Currently, it is bringing back €1850. It seems to round values of .5 downwards instead of upwards? This issue is only happening when the value is .50

Eoin2211
  • 911
  • 2
  • 19
  • 39

2 Answers2

2

The reason you're seeing this odd behavior is because .NET (the framework Blue Prism is based on) uses Banker's Rounding to perform rounding functions by default. From the linked page:

Bankers Rounding is an algorithm for rounding quantities to integers, in which numbers which are equidistant from the two nearest integers are rounded to the nearest even integer. Thus, 0.5 rounds down to 0; 1.5 rounds up to 2.

Thus, when leveraging the rounding functionality in a typical calculation stage, 0.5 will round to 0.

To counter this implementation of rounding, you can use one of two methods:

  • Method #1 - Processing of 0.5 as a separate case

    Use decision stages to determine whether or not the number you're attempting to round has five tenths at the end. If yes, add another .5 to "round up". If there's any other decimal number, proceed with the rounding as normal.

  • Method #2 - Custom rounding implementation

    Create a new custom object with an action that takes your number as an input. Write a code stage to implement the rounding as you see fit. This SO question body has some good code you can start with.

esqew
  • 42,425
  • 27
  • 92
  • 132
  • Thank you for your explanation. I'll opt for the decision stage in this scenario but may revisit in future. – Eoin2211 Nov 06 '18 at 17:34
0

Why not use the RndUp function instead? Although I would expect .5 to be rounded up as well.

Also, the order of the functions in your code is not correct, you are first rounding and then converting to number. The Round function performs (or tries to) do the conversion automatically.

It could look like this:

RndUp(ToNumber(Replace("€1850.50","€","")))
Marek Stejskal
  • 2,698
  • 1
  • 20
  • 30
  • Thanks, I tried RndUp but that is rounding values under .5 up to the next number which is not correct. I have tried a similar syntax to the above also but made no difference to my result. – Eoin2211 Nov 06 '18 at 16:22
  • 1
    Ah, I see. In that case you will have to split the logic into multiple stages, one having a decision whether the fractions are greater than .5 or not. If you are not a fan of that, you can write a code stage for rounding. – Marek Stejskal Nov 06 '18 at 16:39
  • Why doesn't the Round function do this though? 1.5 rounded is 2? According to this it's 1? – Eoin2211 Nov 06 '18 at 16:41