Hi, i'm having a problem, i need to make a variable to get the last number from a bigger number:
example:
Thanks for any help
Hello, one easy way is to convert double to string using the function DoubleToString() and then to get the last character of the string with StringGetChar(). To find the string length use StringLen() function. When you find the last character then you can convert it again to double with StringToDouble().
Perhaps there is another way. MQL language is very flexible. But the above solution will work i am sure.
Hello, one easy way is to convert double to string using the function DoubleToString() and then to get the last character of the string with StringGetChar(). To find the string length use StringLen() function. When you find the last character then you can convert it again to double with StringToDouble().
Perhaps there is another way. MQL language is very flexible. But the above solution will work i am sure.
Hi, i tried what you explained:
double number= 1002; // string numberstring= DoubleToStr(number); // convert in a string string numberstring2=StringGetChar(numberstring,4); //get the forth value Comment (numberstring2);
But don't get the correct number
Hello again,
The first character from a string has position 0. This means that you have to use:
string numberstring2=StringGetChar(numberstring,3); //get the forth value
To get the last character.
Hi, i'm having a problem, i need to make a variable to get the last number from a bigger number:
example:
Thanks for any help
You need the modulo function. 1002 % 10 = 2 or you can use MathMod().
Hi, i can't make it work, i need a code example, can someone give me the complete code?
double a=1002
so please what should i code next to get the last number?
double b= 2?
1) Translate number to string
double number= 1004;
string numberstring= DoubleToStr(number);
2- string numberstring2=StringLen(numberstring);
3- string numberstring3 = StringGetChar( numberstring2,4);
4- Comment (numberstring3);
Doesn't work, how can i solve this?
not tested:
double a= 10003; int lastNum = ((int)a)%10;
not tested:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, i'm having a problem, i need to make a variable to get the last number from a bigger number:
example:
Thanks for any help