creat a decimal point in string

angi

Member
Join Date
Jan 2010
Location
us
Posts
361
Hi guys

I am converting a float data to string in ML1100(for example,12.3), I could handle the integer(12 and 3), but dont know how to creat a decimal point(.) in the string.
Anybody could give some ideas?

thanks
 
So you are using the Integer to ASCII (AIC) instruction for 12 and 3?

You could use the Concatenate (spelling?) ACN instruction and just combine 12, "." and 3 together to get 12.3

Do your math to get the whole number, and the decimal as an integer, which you appear to have already. Then just take the three strings (third being the "." point) and combine them all into a single string in the correct order.
 
1. Multiply the fractional number by the value of the number of decimal places you wish to keep. (1 decimal place - multiply by 10, 2 decimal places - multiply by 100 etc). Move the final value into an integer or Long Word location as appropriate.

2. Create a string from this value using the ACI instruction. Obviously we aren't done yet though. The next instructions depend on your precision. Let's say you want to hundreths (2 places). The last two characters of the string represent the fractional portion.

3. Extract (AEX) characters in the string starting from the first. The number you extract will be the length of the string minus 2 (in this case). These are extracted to one string. These characters represent the integer part of the original number. Extract the last two to another string. These are the frational part.

4. Now we build a string using 'concatenate' (ACN). Concatenate the integer string and a string containing just the period (.) character. Finally concatenate on to that one the fractional portion string (the last two characters).

It may take a bit to get this right. Good Luck. By the way this is so difficult because almost any other method tends to trip up when the fractional part has a zero first in its value (.015).

Tharon's will work if all you want is tenths (one decimal place)
 
Last edited:
Yeah, it was fun trying it the first time until the old zeros tripped me up. Unfortunately I had already put it in place and couldn't figure out why some were coming out wrong. That which is hardest to learn tends to stay the best.
 
decimal point in string

Thanks guys

Tharon, I do not understand how to creat the decimal point in your way,I did the things just like you said. I got the string "123" without the ".", pls give me some more ideas.
 
Make sure your string file is large enough to contain one extra string. Now go into the table, either online or offline (remember to download it afterward) and type in the single character '.' as an entry. I know it's a waste of 81 character spaces but it's the only way. Concatenation only works on strings.
 

Similar Topics

Hello, I’m Trying To make a one cycle program. I’m creating a program that depends on a sensor input so, let’s suppose that sensor detects a thing...
Replies
3
Views
1,541
I'm trying to install TIA portal V13 SP1 on my computer. The system crashes and exits as soon as I try to creat a new project Can anybody help...
Replies
0
Views
2,539
Dear Forum users i have a project, which i have to creat 2 recipe form with about 20 parameters in VBA form. - 1 recipe form used to fill...
Replies
0
Views
4,175
hi folks, I want to create a function like IN1 ---> OUT 1 IN 2 ----> OUT 2 However, I want when I call my function, it has an add to insert how...
Replies
2
Views
3,109
Hello, I have a project in Proworx 32. I want to creat a backup (Archive) for the project but I don't know how to do it. any help in this...
Replies
2
Views
3,633
Back
Top Bottom