Is it possible to get an "exact" value?

 

Greetings. I need help with a problem:

// 0.02 * 4.9 = 0.098
DoubleToStr (0.02 * 4.9, 2); // = 0.1
DoubleToString (0.02 * 4.9, 2); // = 0.1
NormalizeDouble (0.02 * 4.9, 2); // = 0.1

All functions return 0.1. Although (0.02*4.9) = 0.098 and should return 0.09.

Please tell me how to get the exact value which returns my calculator? :)

 

0.02*4.9=0.098 -- not 0.98

output in 2 decimal place format -- 0.098 will be output rounded to 0.10 according to rounding rules

if output in 3-digit format -- the whole number will be output.

 
abolk:

0.02*4.9=0.098 -- not 0.98

output in 2 decimal place format -- 0.098 will be output rounded to 0.10 according to rounding rules

If the output is in 3-digit format -- the whole number will be printed.

Thanks, I corrected the numbers.

That's the problem, you have to take 2 digits after the decimal point. :) Why is it rounded? How can you take a fractional number without rounding and only 2 digits after the decimal point (0.09)?

 
WePlexus:

Thank you, corrected the figures.

That's the problem, you have to take two decimal places. :) Why is it rounded? How can you take a fractional number without rounding and only 2 digits after the decimal point (0.09)?

convert it to a string and take the number of digits
 
WePlexus:

Thank you, corrected the figures.

That's the problem, you have to take two decimal places. :) Why is it rounded? How can you take a fractional number without rounding and only 2 digits after the decimal point (0.09)?

int a=int(0.098/0.01);
   double b=a*0.01;
   Comment(DoubleToString(b,2));
 
sanyooooook:
translate it into a string and take the number of characters you want
Don't you know an easier way?
 
Vinin:
Do you know any easier way
Can you give me a hint? :)
 
valeryk:

And if you do:

int a=int((0.09*5)/0.01);
double b=a*0.01;
Comment (DoubleToString (b,2));

The output is 0.44 instead of the required 0.45.

 
WePlexus:

And if you do:

The output is 0.44 instead of the required 0.45.

int a=int(MathFloor((0.98)/0.001));
   double b=a*0.001;
   Comment(DoubleToString(b,2));
 
valeryk:

0.098, not 0.98. :)

int a = int (MathFloor ((0.098) / 0.001));
double b = a * 0.001;
Comment (DoubleToString (b, 2));

Returns 1, and wanted exact value = 0.09.

 
Vinin:
Do you know an easier way?

that's the first thing that popped into my head, of course there are simpler ones.

It's not complicated either, but maybe it's slower:

   int DIGITS=2;
   string stroka=DoubleToString(0.09845,8);
   int P=StringFind(stroka,".");
   Print(stroka);
    stroka=StringSubstr(stroka,0,P+DIGITS+1);
   Print(StringToDouble(stroka));

возвращает:

2014.10.04 11:32:53.731	normalize EURUSD,H4: 0.09
2014.10.04 11:32:53.731	normalize EURUSD,H4: 0.09845000

Reason: