Sign in to follow this  
Followers 0
John Parker

Long floating point to integer

8 posts in this topic

I need to change a floting point number from 44.3087 to 44.3. I have seen this on the forum before but can't find it again. I am also going to need to display it onto a panelview so I would need to know what integer the 44 and the 3 would be in. Thanks in advance for any help. I am using the SLC 5/04 processor Edited by John Parker

Share this post


Link to post
Share on other sites
Why not just display the floating point in the Panelview and only show 1 decimal place? Why create extra code?

Share this post


Link to post
Share on other sites
It is rounding up the 1 decimal place on the panelview and making it different than the actual PLC. 44.297 shows up as 44.3 on the panelview. I need it to be the same on both so when the operator pushes enter the PLC doesn't reject when the panelview says it is right.

Share this post


Link to post
Share on other sites
If your floating point will never be above 3276.7 you can do this: Assume floating point is 44.297, multiple by ten and store in N7:100, rounding will occur and N7:100 will contain 443. Divide 443 by 10 and place in floationg point, results will be 44.3 display this on your panelview, and use in your logic.

Share this post


Link to post
Share on other sites
44.3 happens to be one of those numbers that CANNOT be represented precisely in IEEE 754 floating point format. The closest you can get is 44.299999. There are lots of numbers that cannot be exactly represnted, and that can create problems when doing comparrisons such as EQU, GEQ, LEQ, etc. When a number is displayed on the panel view the rounding occurs only on the displayed characters, not the actual value. The original value remains unchanged. A little more information would be helpful. Edited by Alaric

Share this post


Link to post
Share on other sites
I am using the 50 mV scale on a tc card to read a load cell. The value is read in raw/proportional and scaled across an scp with calibration values to check weights. The problem I was having was the Panel View would show 44.3 lbs which made it in the acceptable range for the operator to print. The problem with that was the panelview showing 44.3 and the plc actually has 44.2875 or something similar that would round up to 44.3 on the panelview. So the operator is pushing the print button at an acceptable weight and the plc is setting an intgeger to tell the operator thru the panelview that it is not acceptable.

Share this post


Link to post
Share on other sites
OK, I understand now. I might be asking the obvious, but why not then increase the number of displayed digits? The display is coarser than your tolerance when it should be finer than the tolerance. When .02 lbs make a difference then a display that only shows tenths of a pound is insufficient. If thats impossible I understand, but it seems to be obvious. You could also perform some visibility animation on the print button (assuming its an on screen button) so that the button does not become visible unil the weight is acceptable - the value of the tag is still 44.2875 even if it's being displayed as 44.3 on screen.

Share this post


Link to post
Share on other sites
I just tried the multiply and divide method that Ken Moore explained. It seems to be working ok, I am performing linearity and repeatability tests right now to see if it will pass Handbook 44. I would have rather used an onscreen button for print so I could use the pilot on the pushbutton but the recurring problem we have had with retail batch indicators is the operator pushing buttons with anything but their fingers so the pushbutton for print, zero, and tare are standard 800f pushbuttons. Thank you both for all your help.

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