Sign in to follow this  
Followers 0
Chris Elston

Quick and easy way to round a floating point?

4 posts in this topic

Anyone know of an easy way to round to three decimals points using a Floating Point? We have a load cell reading into a F register. But I'll like to round to only three decimals.

Share this post


Link to post
Share on other sites
This might seem a bit cheesy, but it works.  I used 4 CPT statements to accomplish this task.  In the first CPT instruction, I took the input data (assume F8:1 in this case) and built the expression (F8:1 MOD 1.0) * 1000.  I put the result into an integer file (assume N7:3).  In the next CPT instruction, I used the input data again and built the expression: F8:1 MOD 1.0. and put the result in a float (assume F8:0).  This will become useful on the last CPT statement. In the third CPT instruction, I divided the integer file where I loaded the result of the first CPT statement by 1000 and put that answer in another floating point (assume F8:3).  In the fourth and final CPT instruction, I tied all of this together with the following expression: (F8:1 - F8:0) + F8:3.  Of course, I put the result in a floating point (assume F8:4). I realize that this question was posted months ago, but I was just looking around and ran across this post and noticed that no one had replied, so I thought I would.  

Share this post


Link to post
Share on other sites
Hey! Nothing is CHEESY if it works. Thanks for the info. I'll try it when I go to install the machine which should be the week after labor day. I did do something, but I forgot what I did to round it. I am game for playing with logic. Thanks for replying!

Share this post


Link to post
Share on other sites
Here is another way that seems to work. See attachment. MUL F8:0 X 1000 and store in F8:1 MOV F8:1 TO N7:0 DIV N7:0 by 1000 and store in F8:3 Not sure if the attachment will work.

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
Sign in to follow this  
Followers 0