【问题标题】:How do you round a Double down to the nearest integer in VB .NET?如何在 VB .NET 中将 Double 向下舍入为最接近的整数?
【发布时间】:2008-12-18 15:50:27
【问题描述】:

如何在 VB .NET 中将 Double 向下舍入为最接近的整数?

【问题讨论】:

    标签: vb.net double rounding


    【解决方案1】:

    这已经很老了,但是使用Math.Truncate 的公认答案在技术上是不正确的:将舍入向零进行,而不是向下。例如,-1.5 舍入为 -1 而不是 -2。

    为了始终向下舍入,请使用Math.Floor

    【讨论】:

      【解决方案2】:

      我们说的是 VB.NET 还是 VB6?在 VB.NET 中使用Math.Truncate

      【讨论】:

        【解决方案3】:

        这是我们使用的逻辑:

        dim d as decimal = 1.50
        
        dim I as int64 = convert.toint64(D)
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-06-16
          • 2012-01-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-04-03
          相关资源
          最近更新 更多