Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  OPL script writeln() avoid scientific notation for integer

    Posted 02/12/16 02:45 AM

    Originally posted by: ouaigooo


    Hi

    When using writeln(n), with n being a big integer, I got sometimes things like 5.08525e+08

    Is it possible to force to write the whole number and not this notation ?

    With 12.6.3 it seems that it also often prints a .0 at the end of integers.

    Subsidiary question: is there any nice fct for displaying floats ? like printf('%.2f')

    Even writeln(round()) sometimes screw up and displays with many decimals (e.g. .9999999999) ...

    Thanks in advance for your help


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: OPL script writeln() avoid scientific notation for integer

    Posted 02/12/16 10:16 AM

    Hi,

    float n=5.08525e+08;
     
      int n2=ftoi(n);
     
      execute
      {
      writeln(n2);  
      }

    gives

     

    508525000

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: OPL script writeln() avoid scientific notation for integer

    Posted 02/18/16 09:56 AM

    Originally posted by: ouaigooo


    Thanks Alex.

    Actually, it looks like it is a bug of a special hotfix IBM had just released for us.

    IBM support is on it now.

    Kind regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: OPL script writeln() avoid scientific notation for integer

    Posted 02/24/16 09:43 AM

    Originally posted by: ouaigooo


    Any idea about the other question ?

    Subsidiary question: is there any nice fct for displaying floats ? like printf('%.2f')


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: OPL script writeln() avoid scientific notation for integer

    Posted 02/24/16 11:28 AM

    Hi,

    is there a nice way ? Well ...

    There is a way:

    float z=2.5764e7;
     
     
     execute
     {
     var l=Math.log(z)/Math.log(10);
     var z2=Math.round(z/Math.pow(10,Math.round(l)-2)); ///Math.pow(10,Math.round(l)+2);
     var z3=z2/Math.pow(10,2);
     
      write(z3);
     }

    gives

     

    2.58

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: OPL script writeln() avoid scientific notation for integer

    Posted 02/25/16 01:54 AM

    Originally posted by: ouaigooo


    Thanks, but I would rather use var z2=Math.round(z*Math.pow(10,2));

    Anyway:

    Your example does not print the trailing zeros in digits.

    For instance, 0.997467 prints 1 and not 1.00

    So it gets complicated and probably slow if we have to check the number of characters in the string and add trailing zeros or leading spaces if necessary.

     

    It's a pitty there is no fast, embedded function to perform this stuff.

    I guess I'm the only one using OPL Script for printing numbers ...

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: OPL script writeln() avoid scientific notation for integer

    Posted 02/25/16 03:01 AM

    Hi,

    you may try some string operations like the one in documentation for dates:

    execute {

    function converter(dateIn)

    { dateTime = dateIn.split(" ");

    date = dateTime[0];

    time = dateTime[1];

    dateSplit = date.split("-");

    dateReverse = dateSplit.reverse();

    dateNew = dateReverse.join("/") + " " + time;

    return Date.parse(dateNew);

    }

    var d1 = converter("2011-07-06 07:00:00.0");

    writeln(d1);

    }

    you could use an external java call or log a request for enhancement http://www-01.ibm.com/support/docview.wss?uid=swg21659629

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer