
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
3. `string FormatMoney(double amount)` formats a double value `amount` as a string representing a currency amount. It formats the amount with two decimal places, replaces the decimal point with a comma, and inserts spaces every three digits for readability. It also adds the currency symbol obtained from `AccountInfoString(ACCOUNT_CURRENCY)` at the end.
Thank you so much for that. However, these functions are already implemented in the library (even with more robust results than yours), but with different names.
Hello @amrali, thanks for your contribution.
Maybe this is a bug?
I expected second print to be "0.0001".
If is a bug, how to fix? If not, whats wrong in my code?
Thank you.
Hello @amrali, thanks for your contribution.
Maybe this is a bug?
I expected second print to be "0.0001".
If is a bug, how to fix? If not, whats wrong in my code?
Thank you.
Print the hexadecimal representations and you will understand that the spread is far from the true real value 0.0001 (that is because round-off errors during subtraction).
So, you have to use rounding procedures.
There are sublte differences you should notice:
StripError() rounds at the 16th signifiant digit 0.00009999999999998899 (0's are not counted).
Round(x, 16) is rounding at the 16th digits after the decimal point 0.00009999999999998899
Floating-point has an infinite number of decimals. It's you, not understanding floating-point and that some numbers can't be represented exactly. (like 1/10.)
Double-precision floating-point format - Wikipedia
See also The == operand. - MQL4 programming forum (2013)
If you want to see the correct number of digits, convert it to a string with the correct/wanted accuracy.
question about decima of marketinfo() - MQL4 programming forum (2016)
Floating-point has an infinite number of decimals. It's you, not understanding floating-point and that some numbers can't be represented exactly. (like 1/10.)
Double-precision floating-point format - Wikipedia
See also The == operand. - MQL4 programming forum (2013)
If you want to see the correct number of digits, convert it to a string with the correct/wanted accuracy.
question about decima of marketinfo() - MQL4 programming forum (2016)
What is the most optimized way to Print only significant digits with doubles.
This function works great for 99,9% of the numbers but it has issues with round numbers like 1.0000000000
My issues is that I need to strip non significant digits, and for some reason I am not able to do it using only @Trunc,
so I ended up using something like:
It works exactly as needed, giving me the smallest string posible for all numbers, but I was wondering if it can be optimized and still get smallest string with round numbers like 1.00000000
Thank you
Just realized that I am using
Slightly modified version of your
and this is the code
What is the most optimized way to Print only significant digits with doubles.
This function works great for 99,9% of the numbers but it has issues with round numbers like 1.0000000000
My issues is that I need to strip non significant digits, and for some reason I am not able to do it using only @Trunc,
so I ended up using something like:
It works exactly as needed, giving me the smallest string posible for all numbers, but I was wondering if it can be optimized and still get smallest string with round numbers like 1.00000000
Thank you
Sorry, you need to understand what are significant digits as I find your code is confusing the basic concepts.
Thx for you time, and yes, I am not totally sure I understand 'significant digits'
I basically need to 'Print' the shortest possible number. For example:
1.0000000 -> 1
1.0090000 -> 1.009
123.00100 -> 123.001
For me 'significant digits' means: digit that changes the value of a number if removed, so trailing zeros are not significant.
By the way, since Windows last update the function Round(double, int) is causing MT4 to block. The first code I posted was working perfectly and since yesterday night It completely freezes MT4 client.
Thx for you time, and yes, I am not totally sure I understand 'significant digits'
I basically need to 'Print' the shortest possible number. For example:
1.0000000 -> 1
1.0090000 -> 1.009
123.00100 -> 123.001
For me 'significant digits' means: digit that changes the value of a number if removed, so trailing zeros are not significant.
By the way, since Windows last update the function Round(double, int) is causing MT4 to block. The first code I posted was working perfectly and since yesterday night It completely freezes MT4 client.