round up & down

 

HI all, I need to round Bid to the highest and lowest value, as in this example

Bid = 1.24231

I need to obtain 1.24300 (upper round) and 1.24200 (lower round).

I’m trying to use MathRound() and NormalizeDouble() but it doesn’t work.

Could you help me? Thanks!!!

 
Alberto_jazz:

HI all, I need to round Bid to the highest and lowest value, as in this example

Bid = 1.24231

I need to obtain 1.24300 (upper round) and 1.24200 (lower round).

I’m trying to use MathRound() and NormalizeDouble() but it doesn’t work.

Could you help me? Thanks!!!


Try this . . . .

double NewBid;

NewBid = MathRound(Bid * 1000) / 1000;
 
You want to round to the nearest 0.00100 so the equivalent and perhaps slightly more understandable would be.
double tenPips   = 0.00100, // or 10 * pips2dbl
       upperBid  = MathCeil( Bid / tenPips) * tenPips,
       lowerBid  = MathFloor(Bid / tenPips) * tenPips;
 
Thank you very much! I seem it works!
 
WHRoeder:
You want to round to the nearest 0.00100 so the equivalent and perhaps slightly more understandable would be.

I also thank you
 
William Roeder:
You want to round to the nearest 0.00100 so the equivalent and perhaps slightly more understandable would be.
double tenPips   = 0.00100,; // or 10 * pips2dbl
       upperBid  = MathCeil( Bid / tenPips) * tenPips,;
       lowerBid  = MathFloor(Bid / tenPips) * tenPips;

Shouldnt it be like this?

 
codenameCookie: Shouldnt it be like this?

That won't compile. There's only one double, three variables.

Reason: