Rounding in mql4

Rounding in mql4

Manage alerts

Loading saved threads...

Yasin İPEK · External communityPost link
External question — Stack Overflow Stack Exchange Author: Yasin İPEK Original post: https://stackoverflow.com/questions/74480797 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Used in mql4 language NormalizeDouble() function sometimes does not work properly. You can see in the example below. double value=0.9731300000000001; double value2=NormalizeDouble(value,Digits); Print(value2); As a result, although I want to get the result of 0.97313, the result is 0.9731300000000001. How can I fix. double Yuvarla(double Sayi) { double _sayi1=MathRound(Sayi*MathPow(10,Digits)); double _sayi2=_sayi1/MathPow(10,Rakam); return _sayi2; } this method didn't work either
Quote
Report
Yasin İPEK · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Yasin İPEK Original post: https://stackoverflow.com/a/77028262 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. The data type Double saves the result correctly, but I noticed a problem when printing it to the screen. When I write to the screen as DoubleToString(data,Digits()) there is no problem
Quote
Report
I-Kai Wu · External communityPost link
External answer — Stack Overflow Stack Exchange Author: I-Kai Wu Original post: https://stackoverflow.com/a/77906780 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. You need to use DoubleToString then convert it back to double, then it should be fine.
Quote
Report
Ehsan Shayegh · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Ehsan Shayegh Original post: https://stackoverflow.com/a/78155845 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. The second argument of NormalizeDouble () must be 5
Quote
Report
TheLegs · External communityPost link
External answer — Stack Overflow Stack Exchange Author: TheLegs Original post: https://stackoverflow.com/a/79639099 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Results such as this are normal, not only in MQL4 but also in other programming languages such as Python. It relates to the way the floating-point format is built and the approximation that is being done in representing these values. Practically, you should not worry using these values for your calculations, unless for some reason it is critical to have a precision level that goes beyond 10^- Digits . However, if your objective here is to represent them as a string and limit their representation to the amount of Digits in the current market - which is how it looks like based on your examples - then you can use Print(DoubleToString(YourValue, Digits)) .
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: TheLegs Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/a/79639099 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Results such as this are normal, not only in MQL4 but also in other programming languages such as Python. It relates to the way the floating-point format is built and the approximation that is being done in representing these values. Practically, you should not worry using these values for your calculations, unless for some reason it is critical to have a precision level that goes beyond 10^- Digits . However, if your objective here is to represent them as a string and limit their representation to the amount of Digits in the current market - which is how it looks like based on your examples - then you can use Print(DoubleToString(YourValue, Digits)) .

Cancel quote

Checking account access…