Working with StringFormat() & _Digits

 
Morning all,

So I'm working with StringFormat() and wanting to pass various double figures (i.e. prices, moving averages etc) into a string format. I know how StringFormat() works in MQL4 except how to accommodate for 5 an 3 decimal place prices.

I have the following: 

StringFormat("Moving Average: %d %0.5f ",<MA_Period>, <MA_Price>);
The MA_Period is an Int value, but how can I not hardcode the number of decimal places on the floating price (%0.5f or %0.3f)? 

I have read the Help material but it's not particularly helpful.

Many thanks
Moving Average - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
Moving Average - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
  • www.metatrader5.com
The Moving Average Technical Indicator shows the mean instrument price value for a certain period of time. When one calculates the moving average...
 
TheHonestPrussian:
Morning all,

So I'm working with StringFormat() and wanting to pass various double figures (i.e. prices, moving averages etc) into a string format. I know how StringFormat() works in MQL4 except how to accommodate for 5 an 3 decimal place prices.

I have the following: 

The MA_Period is an Int value, but how can I not hardcode the number of decimal places on the floating price (%0.5f or %0.3f)? 

I have read the Help material but it's not particularly helpful.

Many thanks

You have to do that with DoubleToString 

 
TheHonestPrussian but how can I not hardcode the number of decimal places on the floating price (%0.5f or %0.3f)?

The asterisk (*) specifying width, was reported broken; so you need to do it yourself.

string format = stringFormat("Moving Average: %%d %%0.%df ", _Digits);
StringFormat(format,<MA_Period>, <MA_Price>);
 
William Roeder #:

The asterisk (*) specifying width, was reported broken; so you need to do it yourself.

Awesome, thanks