舍入到25、50、75、100 [英] Round to 25, 50, 75, 100

查看:128
本文介绍了舍入到25、50、75、100的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是数学系人士,因此我很难计算出小数点后的数字到25、50、75和100.这不是典型的四舍五入,因为小数点会不会减少,而只会增加.

I'm not a Math person so I'm having a hard time to come up with a calculation to round the decimals to 25, 50, 75 and 100. And this will not be the typical round off because the decimals will not be decreased but only increased.

示例:

如果为11.12,则四舍五入为11.25

if 11.12, round to 11.25

如果为11.34,则四舍五入为11.50

if 11.34, round to 11.50

如果11.52,则四舍五入为11.75

if 11.52, round to 11.75

如果为11.76,则四舍五入为12.00

if 11.76, round to 12.00

这是我的启动方法:

public float RoundNearestCents(String price)
    {
        float srp;

        return srp;
    }

推荐答案

public float RoundNearestCents(double d)
{
  return (double)(Math.Ceiling(d * 4)) / 4;
}

这篇关于舍入到25、50、75、100的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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