Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  Rounding Function

    Posted Mon June 14, 2010 02:23 PM

    Originally posted by: UDOPS


    Is there a rounding function, to a defined number of decimals? I see the "round" function in the documentation, but it is actually an int() or trunc() function.

    Right now I am using Math.round(### * 1000)/1000 to obtain rounding to three decimals.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Rounding Function

    Posted Tue June 15, 2010 06:50 AM

    Originally posted by: SystemAdmin


    Even that does not work all the time.
    Try
    execute{
      var r = 9102.888199999999;
      writeln(" --> ", Math.round( r * 1000)/1000); 
    }
    

    which yields
    --> 9102.888000000001
    


    Question to the OPL-experts: Does the problem come from
    the arithmetics or from the writeln?

    Regards
    Norbert
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Rounding Function

    Posted Tue June 15, 2010 06:54 AM

    Originally posted by: SystemAdmin


    Even more confusing
    78019.90029999999 --> 78019.89999999999
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Rounding Function

    Posted Tue June 15, 2010 05:34 PM

    Originally posted by: UDOPS


    I think I can answer the second example, it is floating point error. I see it frequently, especially in the output of Excel Solver problems which otherwise possess the integrality property (transportation models from textbooks).

    The "000000001" add-on is the result of floating point chip manipulations.

    I have also seen this in older FileMaker Pro databases, where a random addition of two integers a+b would yield (a+b).00000000001. This was quite a stress for invoicing and accounting databases!
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Rounding Function

    Posted Wed June 16, 2010 01:59 AM

    Originally posted by: SystemAdmin


    Thanks for the remarks.
    I agree, it is somewhat annoying.

    Regards
    Norbert
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Rounding Function

    Posted Wed June 16, 2010 12:29 PM

    Originally posted by: UDOPS


    So, to wrap up, there is no appropriate function in OPL/ILOG for rounding to a specified number of significant figures?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer