What is the difference between the String and Real?
I know I can specify how many bytes the string is. But why would someone make a string of 4 bytes rather than making a Real when it's the same thing?
Thanks in advance!
What is the difference between the String and Real?
I know I can specify how many bytes the string is. But why would someone make a string of 4 bytes rather than making a Real when it's the same thing?
Thanks in advance!
In string's you can have characters. Also when you sum up two string's the result would be:
string 1 = "a".
string 2 = "b". the sum would be "ab".
Real numbers, for example:
real 1 = "3.1"
real 2 = "2.0", sum would be "5.1".
And it's not the same thing.
Display More
In string's you can have characters. Also when you sum up two string's the result would be:
string 1 = "a".
string 2 = "b". the sum would be "ab".
Real numbers, for example:
real 1 = "3.1"
real 2 = "2.0", sum would be "5.1".And it's not the same thing.
So could the string be a number as well? I'm just trying to understand why someone would make something a string, and then convert it to a real.
As andreic already wrote, a STRING is a fundamentally different type from a REAL.
To put it simply: a REAL is a number, a single, floating point number, such as 1.234. A STRING is a sequence of characters, which cannot directly contain a floating point number, only letters (roughly. Punctuation and some special characters are also allowed).
So could the string be a number as well? I'm just trying to understand why someone would make something a string, and then convert it to a real.
You can store the string representation of a number in a STRING, so the letters and punctuation characters that together make up how you would write a number down (so a '1' followed by a dot, followed by a '2', followed by a '3', etc), but that is a representation that you cannot use to do arithmetic with. For arithmetic, you need variables of types which are considered numbers, and REAL is one of those.
When a user inputs a number (lets say through the TP, or you read it from a file), it doesn't always automatically end up as a number type variable, but as a STRING. In those cases, you'll first have to convert it to a number, before you can use it with other number type variables (in a formula, or assign it to an integer register, whatever). The routines that can do this essentially interpret the string as you and I would, reading from left-to-right, gradually adding (small) values to a temporary variable (of a number type) until they've completed the conversion. They then return that temporary variable to you.
PS: confusingly, some operators you would normally use for arithmetic, such as addition (+), are defined for (compatible with) STRINGs. But to "add two strings" really means to concatenate them (stick them after each other). Placing one string after the other and returning their combination is obviously very different from a proper addition with numbers, which would return their combined value.