Showing so much digit/number problem

 

Hi friends, 

I want to see and calculate only 5 digit but it creates 15 digit ! How can i reduce the total digit anyone know?

double ma12 () 
   { 
   double ma12 = iMA(_Symbol,_Period,12,0,MODE_EMA,PRICE_MEDIAN,0); 
   return ma12;
   } 

//  Comment (   "Close  :" + Close[0],
//              "\n ma 12  :" + ma12()
//           );


 
cuneytates:

Hi friends, 

I want to see and calculate only 5 digit but it creates 15 digit ! How can i reduce the total digit anyone know?



For Prints, Alerts, Comments etc use DoubleToString().

 
cuneytates: I want to see and calculate only 5 digit but it creates 15 digit ! How can i reduce the total digit anyone know?

Floating-point has an infinite number of decimals, it's you, not understanding floating-point and that some numbers can't be represented exactly. (like 1/10.s)
          Double-precision floating-point format - Wikipedia

See also The == operand. - MQL4 programming forum 2013.06.07

If you want to see the correct number of digits, convert it to a string with the correct/wanted accuracy.
          question about decima of marketinfo() - MQL4 programming forum 2016.05.18

 

I coulnd't able to make it but thank you for replys Mr Watford and Mr Roeder.  

Best regards.

 
cuneytates:

Hi friends, 

I want to see and calculate only 5 digit but it creates 15 digit ! How can i reduce the total digit anyone know?



void OnTick()
  {
//---
   double Sonucma12=ma12 () ;
   
   Print(Symbol()+" MA12 Sonucu:"+DoubleToStr(Sonucma12,_Digits));
    Comment (   "Close  :" + DoubleToStr(Close[0],_Digits),
                 "\n ma 12"  + ":" +DoubleToStr(ma12(),_Digits)
          );
  }
//+------------------------------------------------------------------+
double ma12 () 
   { 
   double ma12 = iMA(_Symbol,_Period,12,0,MODE_EMA,PRICE_MEDIAN,0); 
   return ma12;
   } 

//  Comment (   "Close  :" + Close[0],
//              "\n ma 12  :" + ma12()
//           );

ma12

 
Mehmet Bastem:


Thank you dear Mehmet.