C#怎么总是四舍五入到最接近50 [英] C# how to always round down to nearest 50

查看:234
本文介绍了C#怎么总是四舍五入到最接近50的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了C#四舍五入搜索,但一直没能找到答案我目前的问题。

I've done a search on C# rounding, but haven't been able to find the answer to my current problem.

我想做的事情总是一轮下来我想本轮下跌将是十进制就近50.所有的值。

What I want to do is always round down to the nearest 50. All the values I want to round down will be in decimal.

所以,635.25将是600。

So 635.25 would be 600.

298.42将是250。

298.42 would be 250.

149.56将是100。

149.56 would be 100.

我已经看了在math.round但我怎么会使用如此它总是向下取整为最近的50和再也没有起来?

I've looked at math.round but how would I use that so it always rounds down to the nearest 50 and never up?

推荐答案

除以50值,四舍五入到最接近的整数,并通过50再乘以:

Divide the value by 50, round down to the closest whole number, and multiply by 50 again:

double n = Math.Floor(n / 50.0) * 50.0;

这篇关于C#怎么总是四舍五入到最接近50的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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