rounded numbers

 

Hello,

if i write:

double x=iMA(NULL,0,8,0,MODE_SMA,PRICE_CLOSE,0)

The program takes the point value rounded, the real value is 1.20593 but in the variable x the value is 1.2059.

Why?

Thanks!

 
Vicar:

Hello,

if i write:

double x=iMA(NULL,0,8,0,MODE_SMA,PRICE_CLOSE,0)

The program takes the point value rounded, the real value is 1.20593 but in the variable x the value is 1.2059.

Why?

Thanks!

Hi,


Maybe you should use this:

double x=NormalizeDouble(iMA(NULL,0,8,0,MODE_SMA,PRICE_CLOSE,0),5)

In this way you specify how many digits will use.

I hope it will be useful for you.

Best regards


 
acushnir:


Maybe you should use this:

double x=NormalizeDouble(iMA(NULL,0,8,0,MODE_SMA,PRICE_CLOSE,0),5)

In this way you specify how many digits will use.

Maybe you shouldn't . . .

Maybe you should read the Documentation for Print()

 
Vicar:

Hello,

if i write:

double x=iMA(NULL,0,8,0,MODE_SMA,PRICE_CLOSE,0)

The program takes the point value rounded, the real value is 1.20593 but in the variable x the value is 1.2059.

Why?

Thanks!

Hi Vicar,

When you print it, use conversion function's DoubleToStr(), click that, with Digits for its second parameter.

:D

 
onewithzachy:

Hi Vicar,

When you print it, use conversion function's DoubleToStr(), click that, with Digits for its second parameter.

:D

Or just read the documentation . . . it says this . . .

"Data of double type are printed with 4 decimal digits after point. To output more precisely, use the DoubleToStr() function."

. . . I don't understand peoples reluctance to read the Documentation.

 
RaptorUK:

Or just read the documentation . . . it says this . . .

"Data of double type are printed with 4 decimal digits after point. To output more precisely, use the DoubleToStr() function."

. . . I don't understand peoples reluctance to read the Documentation.

Hi RaptorUK,

Sorry, I didn't remember the print doc said that, all I know it print :D. It's just my long habit since rookie to use conversion function to convert anything. So I reply like that.

. . . I don't understand peoples reluctance to read the Documentation.

Some people want to find out the answer, so it's not reluctant, it's lazy enough to find out that the answer is in the help file - that's why its called the "help file" people !

:D

 
  1. Never use NormalizeDouble, ever.
  2. Convert the numbers before printing.
    string  PriceToStr(double p){ return( DoubleToStr(p, Digits) ); } // Print(PriceToStr(Bid));

Reason: