Rounds up:
decimal rounded = Decimal.Round(originalValue, 3);
if (rounded != originalValue)
{
rounded = Decimal.Round(originalValue + 0.0005, 3);
}
rounds down:
decimal rounded = Decimal.Round(originalValue, 3)
if (rounded != originalValue)
{
rounded = Decimal.Round(originalValue - 0.0005m, 3);
}
Not terribly pretty, but it will work. This sort of thing is easier
where the rounding system always takes the half (e.g. 0.5) _up_, not to
the nearest even digit. It's the latter that requires the first round
attempt and the test, unfortunately.
However, your original code looks as though you are trying to round to
the left of the decimal place, e.g. "to the next higher thousand" or
"to the next higher hundred." In this case, it gets easier:
decimal nextHigherThousand = ((int)(originalValue / 1000m)) * 1000m;
if (nextHigherThousand != originalValue)
{
nextHigherThousand += 1000m;
}
Since to cast to (int) truncates rather than rounding, the first
calculation will either give you the original value back (if it's
already a multiple of 1000) or round down. The test determines whether
the original value was a multiple of 1000 and, if it wasn't, adds 1000
to produce a "round up" effect. This will cost you one cast to int to
perform the truncation, and one (invisible) coercion from int back to
decimal.