Download MetaTrader 5

StringFormat(":%06.3f",v) = "00v.123" how?

To add comments, please log in or register
Have you found an interesting application? Publish it in Code Base - millions of traders will appreciate that!
Carl Schreiber
6610
Carl Schreiber 2014.04.23 13:52 

Hi,

I tried various version to get what is not problem with int-values - leadiing zeros if a value is to small: 11 => "011"?

I have the double v = 5.123 I want to get the string "005.123" using StringFormat("",v);

Anybody knows how?

Thanks in advance,

Gooly

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.23 13:58  
The usual trick is to use string with 00 inside and combines it with respective int whenever the int is below 10.
honest_knave
Moderator
2242
honest_knave 2014.04.23 14:23  
gooly:

Hi,

I tried various version to get what is not problem with int-values - leadiing zeros if a value is to small: 11 => "011"?

I have the double v = 5.123 I want to get the string "005.123" using StringFormat("",v);

Anybody knows how?

Thanks in advance,

Gooly


   double v = 5.123;
   string Test = StringFormat("%07.3f",v);
   Print(Test);
You were 1 digit short. Should be 7 (remember the decimal point counts)
Alain Verleyen
Moderator
30755
Alain Verleyen 2014.04.23 14:31  
gooly:

Hi,

I tried various version to get what is not problem with int-values - leadiing zeros if a value is to small: 11 => "011"?

I have the double v = 5.123 I want to get the string "005.123" using StringFormat("",v);

Anybody knows how?

Thanks in advance,

Gooly

   double var=5.123;
   Print(StringFormat("%07.3f",var));
Carl Schreiber
6610
Carl Schreiber 2014.04.23 17:52  
honest_knave:

You were 1 digit short. Should be 7 (remember the decimal point counts)

Ah - ok! Thank you, angevoyageur too.

As I read it I remember!

To add comments, please log in or register