CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Thu Jul 20, 2017 11:26 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 4 posts ] 
Author Message
 Post subject: rounding up numbers
PostPosted: Mon May 15, 2017 10:30 am 
Offline

Joined: Mon May 01, 2017 11:27 am
Posts: 10
Hi all,

Probably a stupid question but i have some troubles with rounding up numbers. So just like 3/2 = 2
It Always has to be rounded to the biggest number.
Any suggestions here? :) (i don't use the oscat library)

Many thanks.


Top
   
 Post subject: Re: rounding up numbers
PostPosted: Mon May 15, 2017 11:37 am 
Offline

Joined: Thu Apr 13, 2017 8:01 am
Posts: 11
So what do you want ?
If you want to be see 3/2 = 1.5
you have to define LREAL variable.

For example,

variable1 : LREAL;


variable1 := 3/2;

so, you can see variable1 = 1.5


Top
   
 Post subject: Re: rounding up numbers
PostPosted: Mon May 15, 2017 11:40 am 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 230
There are many ways to always round up, but here is one:
Code:
RVal = REAL(3)/2;
IVal = INT(3/2);

If RVal > INT_TO_REAL(IVal) THEN
   IVal := IVal + 1;
END_IF


Top
   
 Post subject: Re: rounding up numbers
PostPosted: Mon May 15, 2017 11:53 am 
Offline

Joined: Mon May 01, 2017 11:27 am
Posts: 10
scott_cunningham wrote:
There are many ways to always round up, but here is one:
Code:
RVal = REAL(3)/2;
IVal = INT(3/2);

If RVal > INT_TO_REAL(IVal) THEN
   IVal := IVal + 1;
END_IF


Thank you. I tried it and it worked :)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 4 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited