Anything I don't understand on MQL5
Hi guys
Why DoubleToString(40/26,3) give me the string 1.000 ? Normally it's 1.538
If I do :
double test = 40/26;
DoubleToString(test,3) it give me also 1.000 and not 1.538
Test:
//+------------------------------------------------------------------+ //| Script 1.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" //--- //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { int int_a=40,int_b=26; double dbl_a=40.0,dbl_b=26.3; Print("int_a / dbl_b ",DoubleToString(int_a / dbl_b)); Print("dbl_a / dbl_b ",DoubleToString(dbl_a / dbl_b)); Print("int_a / int_b ",DoubleToString(int_a / int_b)); } //+------------------------------------------------------------------+
Result:
2021.02.16 13:02:01.325 Script 1 (EURUSD,H1) int_a / dbl_b 1.52091255 2021.02.16 13:02:01.642 Script 1 (EURUSD,H1) dbl_a / dbl_b 1.52091255 2021.02.16 13:02:01.939 Script 1 (EURUSD,H1) int_a / int_b 1.00000000
Documentation: Real Types (double, float)
- www.mql5.com
Hi Vladimir,
thank you for your reply
if I do like this it's ok :
double test=(double)40/26;
DoubleToString(test,3) gives me the string : 1.538 (40 and 26 are double numbers)
but if I do just
double test=40/26;
DoubleToString(test,3) gives me the string : 1.000 (40 and 26 are Integers numbers)
I had never take care about this before ...
Have a good Day
double test=40/26;
DoubleToString(test,3) gives me the string : 1.000 (40 and 26 are Integers numbers)
On MT4 v434, division quotient don't give floating point values(Bug??) - MQL4 programming forum 2012.09.18
Hi guys
Why DoubleToString(40/26,3) give me the string 1.000 ? Normally it's 1.538
If I do :
double test = 40/26;
DoubleToString(test,3) it give me also 1.000 and not 1.538