Just need some simple explanation ...
It is telling you that you're trying to fit a square peg into a round hole.
Example:
int myNumber = 5; string myString = myNumber; // you're trying to force a number into a variable designed to store strings
This will give you the above warning: implicit conversion from 'number' to 'string'.
It is telling (warning) you that it has automatically changed the value of myNumber into a string.
By changing the above code as follows:
int myNumber = 5; string myString = (string)myNumber;
You are expressly changing the number 'myNumber' to a string, so it can be stored in the string variable.
This is known as typecasting. There is no need for a warning, as you have expressly commanded the data type change.
Thanks for your explanation .
I absorb it all perfectly :)
*Mucks Mucks Mucks*
| What toast said is correct. Suppose you wanted to write | int SL; : void onTick(){ int pips = 5; SL = Bid - pips * pips2dbl; : |
| When there is no real change, I'd use a cast. I'm just telling the compiler that the change is intentional but trivial. | int SecondsElapsed(datetime from, datetime to){ long seconds = to - from; return( (int)seconds ); }Since there are no 63 year size bars, I know the value fits in an int, even though datetimes require long. |
| When there is a real change, such as numeric to string, I'd use a function. E.g. datetime to string, do I mean seconds to string (the pre build 600 interpretation) or do I mean a formatted yyyy.mm.dd.... | string PriceToStr(double p){ return( DoubleToStr(p, Digits) ); } string DeltaToPips(double d, string s="+"){ return( SDoubleToStr(d / pips2dbl, digits_pips, s) ); } string DoubleToStrVar(double v, int d=8){ // 1.60000000 -> 1.6 string value = DoubleToStr(v, d); for(int iRight = StringLen(value)-1; true; iRight--){ int c = StringGetChar(value, iRight); if(c != '0'){ if(c == '.') iRight--; break; } } return( StringSubstr(value, 0, iRight+1) ); } string SDoubleToStr(double v, int d, string s="+"){ if (v < 0.) s = ""; return( s + DoubleToStr(v, d) ); } string SDoubleToStrVar(double v, string s="+", int d=8){ if (v < 0.) s = ""; return( s + DoubleToStrVar(v, d) ); }from my code |
https://www.mql5.com/en/articles/1391#3_2
I fix the warning by referring to these articles .
But I don't understand why ( string ) will solve the problem .
Can someone explain the warning " implicit conversion from ' number ' to ' string ' " for me ???
Thanks ~~