Search code examples
blueprism

Blueprism Rounding Issue


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


Solution

  • 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.