圆一个十进制到最近的季度C# [英] Round a decimal to the nearest quarter in C#

查看:72
本文介绍了圆一个十进制到最近的季度C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在C#一个简单的方法来圆一个十进制到最近的季度iex0,X.25,X.50 X.75
为例0.21将轮至0.25,5.03将轮5.0

Is there a simple way in c# to round a decimal to the nearest quarter i.e. x.0, x.25, x.50 x.75 for example 0.21 would round to 0.25, 5.03 would round to 5.0

感谢您事先的任何帮助。

Thanks in advance for any help.

推荐答案

乘以4呢, 它,因为你需要一个整数,然后由四个再除以它:

Multiply it by four, round it as you need to an integer, then divide it by four again:

x = Math.Round (x * 4, MidpointRounding.ToEven) / 4;



四舍五入的各种选项,他们的解释,可以在这个出色答卷的here : - )

这篇关于圆一个十进制到最近的季度C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆