Price value

 
Hi everyone..can anyone help me to write the mql4 code to get only last 3 number after decimal point..

For example:

1.26578

And i want to get only last 3 number as 578..
 
double price = 1.26587;
int last = int(price / _point + 0.5) % 1000; // 126587 % 1000 = 587
 
William Roeder #:
It is not (price / _Point) % 1000 ??? 
 
Idzham Idris #:
Can u teach me about all code that refer to my strategy??im just want to try about my strategy on starategy tester..
Post your code
 
Daniel Cioca #: It is not (price / _Point) % 1000 ??? 

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

The 0.5 rounds any round off to the nearest integer.

 
William Roeder #:

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

The 0.5 rounds any round off to the nearest integer.

Give me an example of a number which will NOT work without your 0.5 rounding... you already asked for integer ...and it doesn't matter if it is an infinity of decimals... you selected the first 5 decimals after coma because you divided initially to _Point (0.00001)...so if you have 1.12345678912345679812345679....... and you divide by 0.00001...you wil have  112345,6789123465798132456798...... and then % 1000... result is 345..but I am not experienced... please show me why do we need to complicate

 
Daniel Cioca #:

Give me an example of a number which will NOT work without your 0.5 rounding... you already asked for integer ...and it doesn't matter if it is an infinity of decimals... you selected the first 5 decimals after coma because you divided initially to _Point (0.00001)...so if you have 1.12345678912345679812345679....... and you divide by 0.00001...you wil have  112345,6789123465798132456798...... and then % 1000... result is 345..but I am not experienced... please show me why do we need to complicate

I'll give you an example

double price=0.90999;
int last = int(price / _Point + 0.5) % 1000;
int last2 = int(price / _Point) % 1000;
Print("last = ",last);
Print("last2 = ",last2);

last will print 999

last2 will print 998

 
Keith Watford #:

I'll give you an example

last will print 999

last2 will print 998

you are right...thank you... understand now... to round up decimals like that   0,(n) ... thanks

 
Daniel Cioca #:

you are right...thank you... understand now... to round up decimals like that   0,(n) ... thanks

I just gave an example. It is William who was right. He put me on the right track years ago with floating point numbers.

 
Keith Watford #:

I just gave an example. It is William who was right. He put me on the right track years ago with floating point numbers.

No...William gave me a bunch of crap to read...you gave me example... and I took the pen and piece o paper and understood  why you are right.


William gave me this : Double-precision floating-point format (sometimes called FP64 or float64) is a computer number format, usually occupying 64 bits in computer memory; it represents a wide dynamic range of numeric values by using a floating radix point.    

So thank you both of you.

 
Daniel Cioca #: William gave me a bunch of crap to read...

I explained why, you want to live in ignorance.

Reason: