0

我对 VB.Net 中正在进行的程序中的数字格式有疑问

我的问题是,我怎样才能通过数字的每百位数字的裁决将它舍入 VB.Net 中的非十进制数:

在两个场景中

*如果第 10 位数字等于或低于 499 (a <= 499 ) 将转到 500 :

例子:

从 1488 --> 1500 从 1,000,320 ----> 1,000,500

*如果第 10 位数字等于或高于 500 (a >= 500) 将变为 1,000:

例子:

从 1500 --> 2000

从 1,000,700 ---> 1,001,000

我用VB6风格,但它不再工作了,

请帮我。

谢谢

4

2 回答 2

0

做这个

// Pass value to round off here
private int ValueRoundOff(int value)
{
    int returnValue = 0;
    bool isHandling = true;
    for (int it = 500; isHandling; it += 500)
       {
           // While it is handling it will check if the value you passed is less 
           // than to 500, if not it will add another 500 to make it 1000 
           // and check again
           if (value < it)
           {
              returnValue = it;
              isHandling = false;
           }
       }
    return returnValue;
}
于 2013-09-20T08:31:32.843 回答
0

鉴于问题中的示例:

Private Function CustomRound(input As Integer)

    Dim roundUpTo500 = (input Mod 1000) < 500

    If (roundUpTo500) Then
        Return Math.Floor(input / 1000) * 1000 + 500
    Else
        Return Math.Round(input / 1000) * 1000
    End If

End Function

给出以下结果:

  CustomRound(1488)    -> 1500
  CustomRound(1500)    -> 2000
  CustomRound(1000320) -> 1000500
  CustomRound(1000700) -> 1001000
于 2013-09-20T09:01:55.063 回答