S sconlon Active Member Licensed User Longtime User Nov 27, 2013 #1 What is the 'correct' way to add two string values together? For various reasons that I won't go into I have to add 2 string values together and assign to a third string, something like: Code: Copy str1 = "6.50" str2 = "0" str3 = str1 + str2 which results in str3 = "6". Is it necessary to assign the string to doubles and then use numberformat2 to convert the result back to a string, eg Code: Copy dbl1 = str1 : dbl2 = str2 dbl3 = dbl1 + dbl2 str3 = NumberFormat2(dbl3,0,2,2,True)
What is the 'correct' way to add two string values together? For various reasons that I won't go into I have to add 2 string values together and assign to a third string, something like: Code: Copy str1 = "6.50" str2 = "0" str3 = str1 + str2 which results in str3 = "6". Is it necessary to assign the string to doubles and then use numberformat2 to convert the result back to a string, eg Code: Copy dbl1 = str1 : dbl2 = str2 dbl3 = dbl1 + dbl2 str3 = NumberFormat2(dbl3,0,2,2,True)
klaus Expert Licensed User Longtime User Nov 27, 2013 #2 What result do you expect ? Do you want to do an arithmethic operation or concatenate two strings ? If you want to do arithmethic operations you should use Doubles. If you want to concatenate two strings you should use dbl3 = dbl1 & dbl2. Upvote 0
What result do you expect ? Do you want to do an arithmethic operation or concatenate two strings ? If you want to do arithmethic operations you should use Doubles. If you want to concatenate two strings you should use dbl3 = dbl1 & dbl2.
S sconlon Active Member Licensed User Longtime User Nov 28, 2013 #3 Thanks Klaus. It was an arithmetic operation I wanted so doubles is the way. But just to satisfy my curiosity, how does the string example above give a result of "6"? Upvote 0
Thanks Klaus. It was an arithmetic operation I wanted so doubles is the way. But just to satisfy my curiosity, how does the string example above give a result of "6"?
klaus Expert Licensed User Longtime User Nov 28, 2013 #4 How did you display str3 ? I just tried it with Log(str3) and I get 6.5 ! Upvote 0
S sconlon Active Member Licensed User Longtime User Nov 28, 2013 #5 klaus said: How did you display str3 ? I just tried it with Log(str3) and I get 6.5 ! Click to expand... I was using the debugger and looking at the value displayed in locals pane. Upvote 0
klaus said: How did you display str3 ? I just tried it with Log(str3) and I get 6.5 ! Click to expand... I was using the debugger and looking at the value displayed in locals pane.
klaus Expert Licensed User Longtime User Nov 28, 2013 #6 I tried it again and looking at the variables I get str3 = 6.5 So I don't know what happens with your project. But, anyway for me arithmetic operations are done with numbers and not with strings. Upvote 0
I tried it again and looking at the variables I get str3 = 6.5 So I don't know what happens with your project. But, anyway for me arithmetic operations are done with numbers and not with strings.