Sign in to follow this  
Followers 0
tunnysting

Clx decimal place

8 posts in this topic

Hi all, probably an easy one but I can't solve it. Is there a way to round values of a real or a float to two decimal places without any code? Cheers, Lee.

Share this post


Link to post
Share on other sites
I don't think so. These processors aren't known for doing much of anything without code. Why the "no code" restriction, if I may ask. Not that I know of a way (yet) to do it in, say a Function Block Diagram, would that be acceptable if it could be done? Bill

Share this post


Link to post
Share on other sites
Just thought there might be a setting without having to write code. There are some load cell displays on HMIs that are to three decimal places, some weighments require this accuracy while others don't. I thought the easiest way would be to round up the tags that didn't need the accuracy but keep the display at three decimal places. I'll try and write code to solve this. Cheers, Lee.

Share this post


Link to post
Share on other sites
There probably IS a way to configure the number of decimals DISPLAYED. What HMI are you using? Bill

Share this post


Link to post
Share on other sites
In a computer rounding a floating point number to two decimal places is not going to change its size or the way it is stored. It is and always will be a 32 bit IEEE-754 floating point number. You can round the display in your HMI software by specifying just two decimal place in the numeric display field. This happens for the characters on the display only, the number is what it is. If you are really that concerned multiply by 1000 and store it as a DINT - but its an extra unnecessary step and a waste of CPU cycles.

Share this post


Link to post
Share on other sites
Thanks all, I'll make the bulk ingredients display rounded one decimal place if I can and the precise ones to three but still leave the HMI display the same. Cheers, Lee.

Share this post


Link to post
Share on other sites
Multiply by 100 dest must be DINT or INT then divide the dest againt with 100 the result will be Real

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