need help!

 
void start()
  {
   double p=1/30;
   Print(p);
  }
   
does anyone know why it shows "P" is 0? I think it would be 0.0333333.... What mistakes did i make? Thanks alot for your time.
 

1 & 30 are ints . . it's type cast . . .

Try . . .

double p=1.0/30.0;
 
Pain:
does anyone know why it shows "P" is 0? I think it would be 0.0333333.... What mistakes did i make? Thanks alot for your time.

It's one of those interesting quirks of MT4 that 1/30 is treated as an integer operation: divide the integer 1 by the integer 30, leading to a rounded-down integer value of zero. In other words, 1/30 is treated as an integer calculation despite the fact that the variable P is declared as a double.

To force MT4 to treat it as a double calculation, the easiest way is to add a decimal point to one or both of the numbers (https://docs.mql4.com/basis/types/double). MT4 will produce the expected result if you write any of the following:

double p=1.0/30;
double p=1/30.0;
double p=1.0/30.0;

 
jjc:

It's one of those interesting quirks of MT4 [...]

[ Thinking about it, it's not a "quirk" at all. It's simply standard behaviour for the C family of languages, including things like C#. Whereas in something like VB.NET, "Dim p As Double = 1 / 30" does generate the value 0.03333 ]
 
Pain:
does anyone know why it shows "P" is 0? I think it would be 0.0333333.... What mistakes did i make? Thanks alot for your time.

Use the decimal points for doubles as suggested by RaptorUK and jjc...

double p= 1.0 / 30.0 ;

Then use DoubleToStr to display as many decimals as you want...

Print (p = DoubleToStr(p,7)); // displays 7 decimals

p= 0.0333333

Hope this helps,

Robert

 

always declare a value as a variable

void start()
  {
   double a=1,
          b=30, 
          p=a/b;
   Print(p);
  }
Reason: