Issue with StringToDouble() - page 3

 
macpee:
The funny thing with the function MathIsValidNumber() is that even string is reported to be a number, as well as numbers. The only things that are not numbers are Mathematical evaluations with mathematical errors. It does not make any sense.

As we discussed in your other thread, MathIsValidNumber() accepts a double for its parameter.

If you push a string into that parameter, the resulting double is going to be a "correct" real number. It might be 0, it might be something else.

So it will pass MathIsValidNumber().

The purpose of MathIsValidNumber() is something quite different. Put bluntly, you are trying to use the wrong tool for the job.

Expanding on the documentation's example, MathArcsin(2.0) fails MathIsValidNumber().

Why?

Arcsine is the inverse function of sine. The range of sine is -1 to 1.

2 is not within the range, so MathArcsin(2.0) is not a valid number. 

 
honest_knave:

As we discussed in your other thread, MathIsValidNumber() accepts a double for its parameter.

If you push a string into that parameter, the resulting double is going to be a real number. It might be 0, it might be something else.

So it will pass MathIsValidNumber().

The purpose of MathIsValidNumber() is something quite different. Put bluntly, you are trying to use the wrong tool for the job.

Expanding on the documentation's example, MathArcsin(2.0) fails MathIsValidNumber().

Why?

Arcsine is the inverse function of sine. The range of sine is -1 to 1.

2 is not within the range, so Arcsine(2) is not a valid number. 

I understand perfectly what you are trying to pass across to me concerning MathIsValidNumber(). You are only explaining further what I have said about the function. There is no need for further explanation on that function. Thank you anyway. So have you found a way of dealing with the leading numbers in a string, say "2Actual". Using the function StringToDouble() outputs 2 as we all know. Any solution to going about it to get 0 rather than 2? I think it needs writing a little code that will replace all leading numbers with NULL, and stop replacing as soon as we encounter other characters. Then we can convert the remaining string using StringToDouble().

To answer the question, I think we need to create a function which replaces digits with NULL in an alphanumeric string.
 
macpee:
I understand perfectly what you are trying to pass across to me concerning MathIsValidNumber(). You are only explaining further what I have said about the function. There is no need for further explanation on that function. Thank you anyway. So have you found a way of dealing with the leading numbers in a string, say "2Actual". Using the function StringToDouble() outputs 2 as we all know. Any solution to going about it to get 0 rather than 2?

The IsValidNumber() code I gave you in the other thread would correctly identify "1st Actual" as not a number.

string test_string = "1st Actual";
Print(IsValidNumber(test_string));

 Result: 2017.02.25 14:26:55.792 Test USDCHF,M1: false

string test_string = " +123.45";
Print(IsValidNumber(test_string));
Result: 2017.02.25 14:31:40.949 Test USDCHF,M1: true

 
macpee:
I think it needs writing a little code that will replace all leading numbers with NULL, and stop replacing as soon as we encounter other characters. Then we can convert the remaining string using StringToDouble().

To answer the question, I think we need to create a function which replaces digits with NULL in an alphanumeric string.

I'm going to be blunt: there doesn't seem to be much "we" going on here. It is mostly "us" giving "you" answers.

You're going to need to start working on the information everyone here as already given you.

Good luck  

 
honest_knave:

I'm going to be blunt: there doesn't seem to be much "we" going on here. It is mostly "us" giving "you" answers.

You're going to need to start working on the information everyone here as already given you.

Good luck  

Ok thanks
Reason: