【问题标题】:Is there is Any possibility for Math.Ceiling Operator with two arguments?有两个参数的 Math.Ceiling 运算符是否有可能?
【发布时间】:2020-05-31 01:21:49
【问题描述】:

我想要14.45 的输出,我有p = 14.445,如果我使用Output=Math.Round(p,2);,我会得到14.44 的输出,

我不能在这里使用Math.Ceiling,因为它包含两个参数。

有什么方法可以得到14.45的输出吗?

【问题讨论】:

    标签: c# math operator-keyword ceil


    【解决方案1】:

    Math.Round 有 3 个参数,让你选择如何舍入 5,你可以得到你想要的行为。否则你也可以(Math.Floor(p * 100) + 1) / 100,但我建议回合:)

    编辑: 代码示例:Math.Round(p, precision, MidpointRounding.AwayFromZero)

    但是MidpointRounding.AwayFromZero 只是一个猜测,因为MidpointRounding 的一些其他值也会从14.445 产生14.45

    【讨论】:

    • 请显示代码以获取 OP 要求的内容。显示 MidpointRounding.AwayFromZero 对于此答案的工作方式至关重要。
    • @Enigmativity 我没有展示任何特定的 MidpointRounding,因为从一个示例中我们无法确定 OP 想要哪一个
    猜你喜欢
    • 1970-01-01
    • 2020-10-05
    • 1970-01-01
    • 2018-08-19
    • 2022-01-13
    • 2021-10-06
    • 2011-05-04
    • 1970-01-01
    • 2019-06-13
    相关资源
    最近更新 更多