0

If I have a double, and want to round it down to the nearest quarter value (0.25), is this possible?

Each of these give me 0.5 and should actually give me 0.25:

Math.Round(0.499999, 2, MidpointRounding.AwayFromZero);
Math.Round(0.499999, 2, MidpointRounding.ToEven);

Is there any notion of always rounding "down"?

This question is related to "nearest" rounding. I don't need that

The "duplicate" is entirely based on NEAREST rounding. that is utterly irrelevant to me. I am not asking about NEAREST. I am asking about always rounding DOWN. Notice that 0.499999 is very NEAR to 0.5 - and that is not what I want. I want 0.49999 to become 0.25 (DOWN)

JacobIRR
  • 8,545
  • 8
  • 39
  • 68

1 Answers1

2
double x = 0.4999;
double answer = Math.Truncate(4*x)/4; // result: 0.25
abelenky
  • 63,815
  • 23
  • 109
  • 159