Rounding Functions

Through the use of Rules and TurboIntegrator processes, Planning Analytics (TM1) supports a lot of different algorithms for data manipulation.

Interestingly, there is no built in functions equivalent to ceiling, floor or truncate so in this post, here are some sample rules (without feeders) for replicating these types of functions.

# Truncation
# Truncate value to x decimal places ie 1000 is 3 decimal place, 100 would be 2 decimal places.  Have to replace each 1xxx instance
# Differs from Int function in that Int returns the largest integer less than equal to specified value i.e truncation does not apply any rounding effect
['Truncated'] = N: Int ( ['Value'] * 1000 ) \ 1000;


# Ceiling ( Round value up to nearest multiple of significance i.e. significance could be whole number 1 or decimal .5)
['Ceiling'] = N: 
   ( Int ( ['Value'] \ ['Significance'] ) 
     - If ( ['Value'] \ ['Significance'] - Int ( [ 'Value' ] \ ['Significance'] ) > 0 
           , -1
           , 0
          ) 
    ) * ['Significance'];


# Floor ( Round value down to nearest multiple of significance i.e. significance could be whole number 1 or decimal .5)
['Floor'] = N: Int ( ['Value']  \ ['Significance'] ) * ['Significance'];    


# Standard rounding using built-in functions
# ROUNDP Function.  Standard function that ronds to the nearest decimal based on the second parameter i. RoundP (1.37, 1) returns 1.4  Can also use minue values ie RoundP (114.4, -1) rteturns 110
['Rounded'] = N: RoundP ( ['Value'], ['Decimal']);


# ROUND Function.  Standard function that rounds to nearest integer i.e. Round ( 1.37 ) returns 1 and Round(1.57) returns 2
['Rounded'] = N: Round ( ['Value'] );
Previous
Previous

Incrementing a Date