Error in a simple "Print"

 
Today I have noticed something strange, for some tests of an expert that I am doing. I wanted to print a value of a double, but to my surprise, you can not.
I explain what I have noticed: only if the value of the double is in the declaration of the variable, it is printed

Before this did not happen, before I could add two integers and when printed the result appeared "double".

Is it a bug or did they just get more demanding when working with integers and doubles?


void OnStart()
  {
//---
   double a=10/20;
   double b=0.5;
   Print("A: ",a,"  B: ",b,"  C: ",10/20,"   D: ",DoubleToString(10/20,2));
   PrintFormat("a= %8.2f   b= %8.2f  c= %8.2f  d= %8.2f",a,b,10/20,DoubleToString(10/20,2));
  }
//+------------------------------------------------------------------+

result:
http://prntscr.com/mg8knf

As it is displayed in the results, only the declared value was printed correctly

I repeat my question: is it something new that is implemented when working with integers and doubles or is it a detail to be corrected?

Captura de pantalla
Captura de pantalla
  • prnt.sc
Capturado con Lightshot
 
Miguel Antonio Rojas Martinez:
Today I have noticed something strange, for some tests of an expert that I am doing. I wanted to print a value of a double, but to my surprise, you can not.
I explain what I have noticed: only if the value of the double is in the declaration of the variable, it is printed

Before this did not happen, before I could add two integers and when printed the result appeared "double".

Is it a bug or did they just get more demanding when working with integers and doubles?


result:
http://prntscr.com/mg8knf

As it is displayed in the results, only the declared value was printed correctly

I repeat my question: is it something new that is implemented when working with integers and doubles or is it a detail to be corrected?

This is because 10/20 evaluates to 0 in programming languages like C, C++, C# and MQLx. The compiler sees two integers, 10 and 20, and so performs an integer division which results in 0. Try 10.0/20.
 
lippmaje:
This is because 10/20 evaluates to 0 in programming languages like C, C++, C# and MQLx. The compiler sees two integers, 10 and 20, and so performs an integer division which results in 0. Try 10.0/20.

OK thank you very much,

I was really convinced (most probably wrongly) that this was resolved "automatically" without passing the integers to double

thanks!

 
Miguel Antonio Rojas Martinez:

OK thank you very much,

I was really convinced (most probably wrongly) that this was resolved "automatically" without passing the integers to double

thanks!

👍
Reason: