Sign in to follow this  
Followers 0
dogbarx

Ascii string to real number

4 posts in this topic

Can an ascii string coming in on channel 0 to st14:0 be converted to a real number? I need to display to two decimal places. I get the entire number into my S14 file but can only seem to convert it to a truncatated integer. TIA Rick

Share this post


Link to post
Share on other sites
You can use the String Search (ASC) function to look for the location of the "." and then use String Extract (AEX) to extract out the decimal portion of the string. After that, do another String to Integer (ACI) conversion to get the decimal portion in integer format. Divide this integer by 100 and add it to your other whole digits integer that you already have and store the result in a floating point.

Share this post


Link to post
Share on other sites
Thanks! That worked. The machine will ship this week. Without the ASCII conversion, we could not have held a 2% tolerance. Thanks again, Rick

Share this post


Link to post
Share on other sites
greetings, Rick, looks like the straight-forward approach that Firetubes suggested has you going ... just one more thing that MIGHT (or might not) cause some unexpected complications ... this is an excellent approach ... just make sure that any NEGATIVE numbers will process correctly ... if your system cannot generate negative numbers then you're home free ... but if it can, you might need to program in some extra kung-fu to make sure that you get the negative values right ... some programmers miss this part completely because they get caught up in the magic of the moment and forget to crank in some negative values during the testing and debug phases ... and also because they're only dealing with small fractional portions which sometimes go unnoticed ... anyway ... there are different ways of handling this, but depending on how you've structured your code, it might be necessary to SUBTRACT the decimal portion from the whole digits integer whenever a negative number rears its ugly head ... best regards, Ron Edited by Ron Beaufort

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