Round to the low
Hi all, could you help me with this problem?
In this case output is 0.05.
I need to obtain 0.04. How can I solve?
Thank you!
Print(NormalizeDouble(0.09/2,2));In this case output is 0.05.
I need to obtain 0.04.
- since 0.09/2 is 0.045, rounding to 2 decimals gives 0.05
- If you need to truncate try
double TruncateDouble(double v, int d){ double mulip = MathPow(10.0,d), trunc = MathFloor(v * multi) / multp; return(trunc); } ///////////// Print(TruncateDouble(0.09/2,2)); // 0.04
- You should change the title of your post "Round to the low" to "Truncate to the low"
@WHRoeder
double TruncateDouble(double v, int d){ // double mulip = MathPow(10.0,d), // trunc = MathFloor(v * multi) / multp; double mulip = MathPow(10.0,d), trunc = MathFloor(v * mulip) / mulip; return(trunc); }
since I am totally mathematically challenged your quickie was totally what needed. I was doing eg,
int i=0.498553*100; double d=i/100.0; Print(d); //0.49
function is now resident in my tools mqh kit bag!
took liberty to c/mul*/mulip/all
was stumped to begin with as totally out of my depth. was do to *ip,*ti,*tp since this is all .ru to me ;-) but got there in the end.
thank you
Hi all, could you help me with this problem?
In this case output is 0.05.
I need to obtain 0.04. How can I solve?
Thank you!