Confusion with Lreal to dword

sarathbabu
2013-12-27
2013-12-30
  • sarathbabu - 2013-12-27

    When ever am using this in program, it is supposed to round up the value and give answer

    eg:Lreal_to_dword(in:=(3/5))

    answer to this is supposed to be 1 but some how in my program it is zero,Can any help me on this

    Thanks
    Sarath

     
  • chab - 2013-12-27

    Maybe (3/5) is handled as an integer first. Which results in 0.

    Try it with a variable like:

    var_in: lreal := 0;
    var_out : dword := 0;
    var_in = 3 / 5;
    var_out := Lreal_to_dword(in:=var_in);
    
     
  • shooter - 2013-12-27

    rounding up a value is simpler with round from the oscat lib.
    it is more predictable, and the way it should be done.
    you are doing a trick and suppose the conversion is good, but a real is totally different from a word.
    the biggest problem is you do not know how 3 is declared as a byte or as a word or anything.
    so make all variables declared this way the result is predicatable.

     
  • sarathbabu - 2013-12-30

    Yes declaring it as integer is the problem.
    Actually i do not need decimal points thats y i tried this conversion

    Thank u

     

Log in to post a comment.