I've modified your code so:
//+------------------------------------------------------------------+ //| doubleBeCarefull.mq4 | //| Copyright © 2009, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #include <stdlib.mqh> //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { //---- double v1; int k; v1 = (1.0006-1.0005); //v1 = 0.0001 Print(v1); //OK: output 0.0001 v1 /= 0.0001; //v1 = 1.0000 Print(v1); //OK: output 1 k = v1 ; // ERROR: Here k should equal to 1, but it is equal to 0. !!!!!!!! Print("Print v1=",v1); //OK: output 1 Print("DoubleToStrMorePrecision(v1,16)=",DoubleToStrMorePrecision(v1,16)); Print(k); //?????: output 0. return(0); //---- return(0); } //+------------------------------------------------------------------+
and here is result:
19:05:36 Compiling 'doubleBeCarefull'
19:11:01 doubleBeCarefull GBPUSD,H4: loaded successfully
19:11:01 doubleBeCarefull GBPUSD,H4: 0.0001
19:11:01 doubleBeCarefull GBPUSD,H4: 1
19:11:01 doubleBeCarefull GBPUSD,H4: Print v1=1
19:11:01 stdlib GBPUSD,H4: loaded successfully
19:11:01 doubleBeCarefull GBPUSD,H4: DoubleToStrMorePrecision(v1,16)=0.9999999999998898
19:11:01 doubleBeCarefull GBPUSD,H4: 0
19:11:01 doubleBeCarefull GBPUSD,H4: uninit reason 0
19:11:01 stdlib GBPUSD,H4: uninit reason 0
19:11:01 stdlib GBPUSD,H4: removed
19:11:01 doubleBeCarefull GBPUSD,H4: removed
Check it yourself, pleasae.
Oh, I see! Thank you Rosh.
So It was Print() function trick me.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
{
double v1;
int k;
v1 = (1.0006-1.0005); //v1 = 0.0001
Print(v1); //OK: output 0.0001
v1 /= 0.0001; //v1 = 1.0000
Print(v1); //OK: output 1
k = v1 ; // ERROR: Here k should equal to 1, but it is equal to 0. !!!!!!!!
Print(v1); //OK: output 1
Print(k); //?????: output 0.
}