marcinmrag

59/5000 Czy chodziło Ci o: jak mogę zaokrąglić wartość realu do 2 miejsc po przecinku? how can I round up the real value to 2 decimal places?

3 posts in this topic

Hello !

how can I round up the real value to 2 decimal places? I have value of angle from Robot and I would like to have a confirmation of position. But Is a lot of decimal places and It take a long time when two value get equel.

 
 
 

Share this post


Link to post
Share on other sites

I would multiply it by 100 as a floating point number and then use the ROUND instruction.  This will convert it to a LINT or DINT and then just compare it to a LINT / DINT.  

 

3.14159

x 100 = 314.159

Using ROUND becomes 314.  Then use an = instruction to compare it to LINT#314.

Share this post


Link to post
Share on other sites
On ‎1‎/‎16‎/‎2018 at 11:39 AM, marcinmrag said:

But Is a lot of decimal places and It take a long time when two value get equel.

For this reason, there is a fundamental reason not to use "= x" comparison to a REAL value. If you need the precision then do as Michael says. Typically I will perform "<= x", ">= x" or compare a window ">= && < y".

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now