圆形数字直到下一个0.25 in .Net [复制]

时间:2020-12-25 18:17:53

This question already has an answer here:

这个问题在这里已有答案:

How can I round decimal up (not down) to 0.25?

如何将十进制数(不是向下)舍入到0.25?

1.26 -> 1.50

1.45 -> 1.50

1.15 -> 1.25

1.00 -> 1.00

1.55 -> 1.75

1.77 -> 2.00

I have tried following function but no success.

我试过以下功能,但没有成功。

Decimal.Round(x * 4, MidpointRounding.ToEven) / 4

1 个解决方案

#1


Use the Ceiling method to round up:

使用Ceiling方法向上舍入:

Decimal.Ceiling(x * 4m) / 4m

#1


Use the Ceiling method to round up:

使用Ceiling方法向上舍入:

Decimal.Ceiling(x * 4m) / 4m