- Numbers to strings and vice versa
- Normalization of doubles
- Date and time
- Color
- Structures
- Enumerations
- Type complex
Normalization of doubles
The MQL5 API provides a function for rounding floating point numbers to a specified precision (the number of significant digits in the fractional part).
double NormalizeDouble(double number, int digits)
Rounding is required in trading algorithms to set volumes and prices in orders. Rounding is performed according to the standard rules: the last visible digit is increased by 1 if the next (discarded) digit is greater than or equal to 5.
Valid values of the parameter digits: 0 to 8.
Examples of using the function are available in the ConversionNormal.mq5 file.
void OnStart()
|
Due to the fact that any real number has a limited internal representation precision, the number can be displayed approximately even when normalized:
...
|
This is normal and inevitable. For more compact formatting, use the functions DoubleToString, StringFormat or intermediate casting to (float).
To round a number up or down to the nearest integer, use the functions MathRound, MathCeil, MathFloor (see section Rounding functions).