Skip to Main Content
Need Support? Let’s guide you to the right answer or agent.
Status Needs review
Categories General
Created by Guest
Created on Dec 28, 2023

Item Expression Math Function Roundup / Ceiling math

Expression Math Function Roundup / Ceiling math

It is known that processing slows when using nested IIF statements. In order to simplify the expressions functions for Roundup and Increments for Ceiling.Math with are needed.

  • Roundup function with a precision

    • Roundup(100.03,1) = 100.1

  • math function like excel

    • MATH(16.25,15,0) = 30

Roundup function with a precision instead of nested iif:

IIf(this.RoundingPrecision=1,System.String.Format("{0:0.0}",System.Math.Ceiling(this.CompQuantity*10) / 10)

Increment rounding: Similar to CEILING.MATH in Excel

I would want to round the length of a line to an interval of 15. In excel it would be =CEILING.MATH(A2,15,0) A line length of:

  • 99 = 15

  • 4 = 15

  • 25 = 30

  • 18 = 30

  • 8 = 45

  • 44 = 45


Generic example for interval of 15: iif(x mod 15 = 0, x, (x \ 15 +1)*15)

More specific example of increment:

System.Math.Round(System.Math.Ceiling(this.CompQuantity),this.RoundingPrecision), (this.CompQuantity \this.RoundingIncrement +1)*this.RoundingIncrement))


IIf((this.RoundingConservative=True) && (this.RoundingIncrement=0),(IIf(this.RoundingPrecision=0,System.String.Format("{0:0}",System.Math.Ceiling(this.CompQuantity)),(IIf(this.RoundingPrecision=1,System.String.Format("{0:0.0}",System.Math.Ceiling(this.CompQuantity*10) / 10),(IIf(this.RoundingPrecision=2,System.String.Format("{0:0.00}",System.Math.Ceiling(this.CompQuantity*100) / 100),(IIf(this.RoundingPrecision=3,System.String.Format("{0:0.000}",System.Math.Ceiling(this.CompQuantity*1000) / 1000),(IIf(this.RoundingPrecision>=4,System.String.Format("{0:0.0000}",System.Math.Ceiling(this.CompQuantity*10000) / 10000),-1)))))))))),IIf((this.RoundingConservative=False) && (this.RoundingIncrement=0),System.Math.Round(this.CompQuantity,this.RoundingPrecision),IIf((this.RoundingIncrement=0) || (this.CompQuantity mod this.RoundingIncrement = 0), System.Math.Round(System.Math.Ceiling(this.CompQuantity),this.RoundingPrecision), (this.CompQuantity \this.RoundingIncrement +1)*this.RoundingIncrement)))

  • Guest
    Reply
    |
    Feb 6, 2025

    Still waiting for an out of the box solution in a symbol provider for this, below is sample code:


    /// <summary>Rounds up a number to the specified precision.</summary>

    public static double RoundUpWithPrecision(double arg1, int arg2)

    {

    double factor = Math.Pow(10, arg2);

    return Math.Ceiling(arg1 * factor) / factor;

    }

    /// <summary>Rounds up a number to the nearest multiple with the specified precision.</summary>

    public static double CeilingMath(double number, double multiple, int precision)

    {

    double result = Math.Ceiling(number / multiple) * multiple;

    return Math.Round(result, precision);

    }