eccan

float to string in SLC

7 posts in this topic

Hello All I have a 7 digit number in a F8:0. Is there anyway to get this into a string (ST12:0?) Soemthing like AIC does with an integer to a string. Using a SLC504 Thanks

Share this post


Link to post
Share on other sites
There are some other samples but I just read THIS sample for the Micrologix 1100 yesterday. It is for taking a floating to a string for display on the LCD. You should be about to adapt this code the the SLC

Share this post


Link to post
Share on other sites
The easiest option if the float is within range is to move the float into an integer and convert that, then subtract the integer to be left with the decimal part and multiply it by 1000 and convert that. Then join the strings together. Quite quick and better than nothing.

Share this post


Link to post
Share on other sites
It is a 8 digit positive number. The problem I found with splitting it up and putting it in 2 integer files is the first integer file rounds off its last digit.

Share this post


Link to post
Share on other sites
I'm not sure if the unround value is left in S:13 (or perhaps S:14) when using floats but it should be relatively easy to subtract your rounded number from the original to determine if it was rounded and then adjust it. Edited by Spedley

Share this post


Link to post
Share on other sites
See how THIS on works for you. As far as the rounding you need to decide how many digits you want to the right of the decimal. I can't think of a way to vary the number of digits to the right of the decimal depending on the values without adding a lot of complication

Share this post


Link to post
Share on other sites
Thanks TW I don't know how I missed that in my knowledgebase search EC

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