MathTrunc does not work

To add comments, please log in or register
DeltaElectronics
159
DeltaElectronics  

Hello to everybody...

I would like get the integer part of a double number, so I guessed to use the library function MathTrunc() (https://www.mql5.com/en/docs/standardlibrary/mathematics/stat/mathsubfunctions/statmathtrunc)

but such function is not recognized by the compiler.

How could I use it ?

Vitalii Ananev
10028
Vitalii Ananev  
DeltaElectronics:

Hello to everybody...

I would like get the integer part of a double number, so I guessed to use the library function MathTrunc() (https://www.mql5.com/en/docs/standardlibrary/mathematics/stat/mathsubfunctions/statmathtrunc)

but such function is not recognized by the compiler.

How could I use it ?

Use the function MathRound()

DeltaElectronics
159
DeltaElectronics  
Vitalii Ananev:

Use the function MathRound()

It's not the same identical thing...

I would like get the integer part of a double number, whitout the rounding...

For example MathRound(4.9) gets 5; instead my goal is to get 4 !!!

And, in addition, I saw that MathTrunc() is well documented in the site; so I wondered the compiler does not compile it.

Demos Stogios
210
Demos Stogios  

Hello

a) You have to include Math.mqh in your program, here are the docs

MQL5 Reference  /  Language Basics  /  Preprocessor / Including Files (#include)


b) If you only wanted to use MathTrunc() MathFloor() is like truncation

Vitalii Ananev
10028
Vitalii Ananev  
DeltaElectronics:

It's not the same identical thing...

I would like get the integer part of a double number, whitout the rounding...

For example MathRound(4.9) gets 5; instead my goal is to get 4 !!!

And, in addition, I saw that MathTrunc() is well documented in the site; so I wondered the compiler does not compile it.

I suspect that the MathTrunc () function is not present in MQL4. In the code editor functions directory, I did not find such a function. But in the directory on the site it is.

kypa
1079
kypa  

If you want to use a library function you should probably include the library.

Otherwise MathFloor/floor (MathCeil/ceil for negative numbers) will give you the same result. Or just casting into integer.

Anthony Garot
3285
Anthony Garot  
DeltaElectronics:

I would like get the integer part of a double number

https://www.mql5.com/en/forum/263176#comment_7998295
To add comments, please log in or register