Probably because the first one only contains the number 1 whereas the others are letters.
The second one only contains the number 2 and the rest are letters.
The second one only contains the number 2 and the rest are letters.
Keith Watford:
Probably because the first one only contains the number 1 whereas the others are letters.
The second one only contains the number 2 and the rest are letters.
Yes, but both inputs are strings and it they should return zero values
Probably because the first one only contains the number 1 whereas the others are letters.
The second one only contains the number 2 and the rest are letters.
macpee:
Yes, but both inputs are strings and it they should return zero values
Parameters have to be strings for StringToDouble()Yes, but both inputs are strings and it they should return zero values
The function converts string containing a symbol representation of number into number of double type.
macpee: Yes, but both inputs are strings and it they should return zero values
As @Keith Watford, pointed out, the strings start with numerical digits, so the assumption is that in converts the initial part as that of a valid number and disregards the rest.EDIT: Looks like @Keith Watford posted an answer at the same time (and just before).
StringToDouble (and StrToDouble) will start from the left-most character.
- It will skip whitespace at the start of a string, until a different character is encountered.
- It will interpret one '+' or '-' as a positive or negative sign, but only when it is the first non-whitespace character encountered.
- It will interpret number(s) in their literal sense.
- It will interpret one '.' as a decimal point.
- As soon as it encounters whitespace after a non-whitespace character, or a 2nd decimal point, or a '+' or '-' sign that is not the first non-whitespace character, or any other character that is not a number it will disregard the rest of the string.
- Note: it disregards the rest of the string, not the entire string.
Examples
String | Double | Reason |
---|---|---|
"x12345" | 0.0 | First character was a letter |
"123x45" | 123.0 | Encountered a letter after 123 |
" 123" | 123.0 | Whitespace ignored at start of string |
" 12 3" | 12.0 | Encountered whitespace after 12 |
"123.45" | 123.45 | One decimal point is OK |
"123.4.5" | 123.4 | Encountered a second decimal point |
"1,234.50" | 1.0 | Encountered a comma |
Not documented (to my knowledge)
Fernando Carreiro:
As @Keith Watford, pointed out, the strings start with numerical digits, so the assumption is that in converts the initial part as that of a valid number and disregards the rest.
EDIT: Looks like @Keith Watford posted an answer at the same time (and just before).
Thanks, I didn't realise that it actually had to start with a number as a string.As @Keith Watford, pointed out, the strings start with numerical digits, so the assumption is that in converts the initial part as that of a valid number and disregards the rest.
EDIT: Looks like @Keith Watford posted an answer at the same time (and just before).
Of course macpee should have investigated and done some tests.
honest_knave:
Seems that Honest Knave has already done some investigation.StringToDouble (and StrToDouble) will start from the left-most character.
- It will skip whitespace at the start of a string, until a different character is encountered.
- It will interpret number(s) in their natural sense.
- It will interpret one '.' as a decimal point.
- As soon as it encounters whitespace after a number/decimal point, or a 2nd decimal point, or any other character that is not a number it will disregard the rest of the string.
- Note: it disregards the rest of the string, not the entire string.
Examples
String | Double | Reason |
---|---|---|
"x12345" | 0.0 | First character was a letter |
"123x45" | 123.0 | Encountered a letter after 123 |
" 123" | 123.0 | Whitespace ignored at start of string |
" 12 3" | 12.0 | Encountered whitespace after 12 |
"123.45" | 123.45 | One decimal point is OK |
"123.4.5" | 123.4 | Encountered a second decimal point |
"1,234.50" | 1.0 | Encountered a comma |
Not documented (to my knowledge)
Well done, a great answer.
honest_knave:
I am wondering what could be a real world usage of this possibility of the function ? I never use it.StringToDouble (and StrToDouble) will start from the left-most character.
- It will skip whitespace at the start of a string, until a different character is encountered.
- It will interpret number(s) in their natural sense.
- It will interpret one '.' as a decimal point.
- As soon as it encounters whitespace after a number/decimal point, or a 2nd decimal point, or any other character that is not a number it will disregard the rest of the string.
- Note: it disregards the rest of the string, not the entire string.
Examples
String | Double | Reason |
---|---|---|
"x12345" | 0.0 | First character was a letter |
"123x45" | 123.0 | Encountered a letter after 123 |
" 123" | 123.0 | Whitespace ignored at start of string |
" 12 3" | 12.0 | Encountered whitespace after 12 |
"123.45" | 123.45 | One decimal point is OK |
"123.4.5" | 123.4 | Encountered a second decimal point |
"1,234.50" | 1.0 | Encountered a comma |
Not documented (to my knowledge)
Each time I am using StringToDouble() it's because I know there is a double inside the string (from a CSV file for example).
Alain Verleyen:
I am wondering what could be a real world usage of this possibility of the function ? I never use it.
Each time I am using StringToDouble() it's because I know there is a double inside the string (from a CSV file for example).
Yes, I use it when reading from files and also getting a value from OBJ_EDIT.I am wondering what could be a real world usage of this possibility of the function ? I never use it.
Each time I am using StringToDouble() it's because I know there is a double inside the string (from a CSV file for example).
Apart from that I don't think that I use it.
Alain Verleyen:
I am wondering what could be a real world usage of this possibility of the function ? I never use it.
Each time I am using StringToDouble() it's because I know there is a double inside the string (from a CSV file for example).
I am wondering what could be a real world usage of this possibility of the function ? I never use it.
Each time I am using StringToDouble() it's because I know there is a double inside the string (from a CSV file for example).
It doesn't really achieve anything beyond a simple typecast.
Like @Keith Watford I use it in conjunction with OBJ_EDIT boxes. But I opt for the simple typecast rather than the function call.
Keith Watford:
Seems that Honest Knave has already done some investigation.
Well done, a great answer.
Thanks, I had to modify my original post as I forgot about + / -
Seems that Honest Knave has already done some investigation.
Well done, a great answer.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Moreover, why does the function
and so on...