Programming question

In what language?

Edit: pardon my ignorance I didn't pay attention to which category this was posted in. ;-)
Anyway I'm not familiar with MetaTrader's MQL 4, but you should probably look for a padding function that converts the integer into a string and prepends the required number of zero's to match the required string length.

Ruben.
 
Last edited:
I checked out the MQL docs a bit and came up with this:

string Pad(int number, int requiredLength)
{
string strNumber = number;
string strNewNumber = "";
int intDiff = StringLen(strNumber) - requiredLength;
if (intDiff > 0)
{
for (intCurChar = 0; intCurChar < intDiff; intCurChar++)
{
strNewNumber += "0";
}
strNewNumber += strNumber;
}

return strNewNumber;
}

Please note that I didn't test this and this is the first piece of MQL I ever wrote, but it should give you an idea of how to do this. Is this what you had in mind?

Ruben.
 
Yes, thanks, it's pretty much the sort of thing. I will have to investigate the precise details. Shame it can't be set to display numbers formatted such that 3 digits are always showing.
 
Yeah most languages have builtin formatting functions for integers, but I couldn't find them in the MQL reference. Then again, maybe there is and I just didn't see it. Someone with some MQL experience might be able to tell you.

Ruben.
 
In that case a custom function like the example I made should do the trick. Again not tested, so it might bother your cat or even drink all the beer from your fridge. Use at your own risk. ;-)

Ruben.
 
Top