Number output to decimal places

 

Hello everyone,


how can I give numbers (long, double, int) a specific format, e.g. always 2, 3 or 4 decimal places and a thousand separator.


Is there a command for this or do I have to build a small function for this? With the second one, I'm always afraid that I'll use up too much program running time.


greetings mosquito

 
Muecke82: how can I give numbers (long, double, int) a specific format, e.g. always 2, 3 or 4 decimal places and a thousand separator.
    1. Floating point has an infinite number of decimals, it's you were not understanding floating point and that some numbers can't be represented exactly. (like 1/10.)
                Double-precision floating-point format - Wikipedia, the free encyclopedia

      See also The == operand. - MQL4 programming forum (2013)

    2. Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.

    3. SL/TP (stops) need to be normalized to tick size (not Point) — code fails on non-currencies.
                On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum #10 (2011)

      And abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum (2012)

    4. Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on non-currencies. So do it right.
                Trailing Bar Entry EA - MQL4 programming forum (2013)
                Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 programming forum (2012)

    5. Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
                (MT4 2013)) (MT5 2022))

    6. MathRound() and NormalizeDouble() are rounding in a different way. Make it explicit.
                MT4:NormalizeDouble - MQL5 programming forum (2017)
                How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum (2017)

    7. Prices you get from the terminal are already correct (normalized).

    8. PIP, Point, or Tick are all different in general.
                What is a TICK? - MQL4 programming forum (2014)

  1. NumbersSeparator() function for Print big numbers - MQL4 programming forum (2014)
 

Man, why did I write in English, that was an automatic translation error, sorry.

that's a lot to read and study. that takes a while for me.

My goal is to create a small table that will be printed out.

Print ( "## ************************************************************************************************************** ##" );
Print ( "## Buy        Open        Tp          Sl          ~G&V    |  Sell       Open        Sl          Tp          ~G&V  ##" ); 

However, I have found that it is not just the decimal places that are a problem, but also the pre-decimal places, as these can vary.

 
Muecke82 #:

Man, warum habe ich in Englisch geschrieben, das war ein Fehler der automatischen Übersetzung, sorry.

das ist viel zum lesen und Studiren. das dauert eine Weile bei mir.

Mein ziel ist es eine kleine tabelle zu erstellen die per Print ausgegeben wird.

Ich habe jedoch festgestellt, dass nicht nur die Nachkommastellen ein Problem darstellen, sondern auch die Vorkommastellen, da diese variieren können.

This is the English forum detectable by the top right corner:

and the url: https://www.mql5.com/en/forum/ ... the German url would be https://www.mql5.com/de/forum ..

Look for StringFormat() or PrintFormat().

MQL5 forum
MQL5 forum
  • www.mql5.com
MQL5: Forum on automated trading systems and strategy testing
 
Oh, that was my mistake, sorry. Thanks for pointing that out.


Oh, more to read, ... THANK YOU, I'll have a look and work through it.
 
I think PrintFormat() is right for me, but I don't quite understand the composition yet.


Exercise 1:

Code:
double Test = 1.132456789;
Print("This is: ", Test, " (two decimal places)");

Output:
This is: 1.12 (two decimal places)


Exercise 2:

Code:
double Test = 1.132456789;
Print("This is: ", Test, "(Leading zeros & two decimal places)");

Output:
This is: 00001.12 (leading zeros & two decimal places)
Reason: