Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Real number with digit limit

jeanmy21
2014-05-05
2014-05-17
  • jeanmy21

    jeanmy21 - 2014-05-05

    Hello,
    I am looking for a function to limit the number after the decimal point of a real.
    The input parameters of this function are Val type and Reel NBdigit of type Int.
    The output parameter is a real
    Here is an example My_Fonction (3.45789, 2). The output value is 3.45.

     
  • jeanmy21

    jeanmy21 - 2014-05-06

    J'ai fait ma function

    Voici le code :

    PROGRAM Real_To_Real
    VAR_INPUT
       rIn : REAL;      
       Digit: INT;         
    END_VAR
    VAR_OUTPUT
      rOut       : REAL;      
    END_VAR
    VAR
       d1 : DINT;
       r0,r1,r2,Rdigit: REAL;               
    END_VAR
    //**********************************************************************************
    //*********************************************************************************
    rdigit   :=INT_TO_REAL(Digit);
    r0 := EXPT(10,rdigit); 
    r1 := rIn * r0;
    d1 := TRUNC(r1);
    r2 := DINT_TO_REAL(d1);
    rout := r2 / r0;
    
     
  • shooter

    shooter - 2014-05-17

    have a look at w www.oscat.de w for a lot of functions you can use.

     

Log in to post a comment.