Excel公式在数字(30)后取整,而不是50到最近的100
我认为标题说明了一切,在这种情况下,是否有可能将数字30四舍五入到最接近的100?我相信ROUND函数在默认情况下会在50后循环。我正在寻找一个Excel公式,可以做到这一点 对不起,我应该提供一些例子 考虑以下数字,它将始终是整数:Excel公式在数字(30)后取整,而不是50到最近的100,excel,excel-formula,excel-2010,Excel,Excel Formula,Excel 2010,我认为标题说明了一切,在这种情况下,是否有可能将数字30四舍五入到最接近的100?我相信ROUND函数在默认情况下会在50后循环。我正在寻找一个Excel公式,可以做到这一点 对不起,我应该提供一些例子 考虑以下数字,它将始终是整数: Given Expected 120 100 130 200 131 200 5410 5400 5430 5500 对于现在提供的样本: =IF(1*RIGHT(A1,2)<30,A1-RIGHT(A1,2),A1
Given Expected
120 100
130 200
131 200
5410 5400
5430 5500
对于现在提供的样本:
=IF(1*RIGHT(A1,2)<30,A1-RIGHT(A1,2),A1+100-RIGHT(A1,2))
对于现在提供的样本:
=IF(1*RIGHT(A1,2)<30,A1-RIGHT(A1,2),A1+100-RIGHT(A1,2))
编辑:
这只是你可能要走的方向。它指的是正整数。但它需要大量的工作,例如,在一个案例中,当我将因子改为2时,dblDif最终是1.99999999,而不是2。因此,仅将此作为一个想法:
Function R30(Num As Double, Round As Integer, Optional Factor As Integer) _
As Double
If IsMissing(Factor) Then Factor = 3
Dim dblNum As Double
Dim dblDif As Double
dblNum = Num / 10 ^ Round
dblDif = (dblNum - Int(dblNum)) * 10 ^ Round
If dblDif <> 0 Then
If dblDif < Factor * 10 ^ (Round - 1) Then
R30 = Int(dblNum) * 10 ^ Round
Else
R30 = (Int(dblNum) + 1) * 10 ^ Round
End If
Else
R30 = Num
End If
End Function
Sub R30use()
Debug.Print R30(133, 1, 3)
End Sub
编辑:
这只是你可能要走的方向。它指的是正整数。但它需要大量的工作,例如,在一个案例中,当我将因子改为2时,dblDif最终是1.99999999,而不是2。因此,仅将此作为一个想法:
Function R30(Num As Double, Round As Integer, Optional Factor As Integer) _
As Double
If IsMissing(Factor) Then Factor = 3
Dim dblNum As Double
Dim dblDif As Double
dblNum = Num / 10 ^ Round
dblDif = (dblNum - Int(dblNum)) * 10 ^ Round
If dblDif <> 0 Then
If dblDif < Factor * 10 ^ (Round - 1) Then
R30 = Int(dblNum) * 10 ^ Round
Else
R30 = (Int(dblNum) + 1) * 10 ^ Round
End If
Else
R30 = Num
End If
End Function
Sub R30use()
Debug.Print R30(133, 1, 3)
End Sub
也许是这样的 它检查整数中的最后两个数字是否等于30或更大。如果是这样的话,它将接近100。否则它将四舍五入到最接近的100
=IF(VALUE(RIGHT(A1,2))>=30,ROUNDUP(A1,-2),ROUNDDOWN(A1,-2))
也许是这样的 它检查整数中的最后两个数字是否等于30或更大。如果是这样的话,它将接近100。否则它将四舍五入到最接近的100
=IF(VALUE(RIGHT(A1,2))>=30,ROUNDUP(A1,-2),ROUNDDOWN(A1,-2))
我已经编写了这个自定义函数,它还考虑了0以下的数字
Function CustomRound(lngValue As Long)
Dim lngValueMin As Long
Dim lngValuePart As Long
Dim intNeg As Integer
If lngValue < 0 Then
lngValue = lngValue * -1
intNeg = -1
Else
intNeg = 1
End If
lngValueMin = lngValue - Right(lngValue, 2)
lngValuePart = Right(lngValue, 2)
If lngValuePart < 30 Then
CustomRound = lngValueMin * intNeg
Else
CustomRound = (lngValue + (100 - lngValuePart)) * intNeg
End If
End Function
我已经编写了这个自定义函数,它还考虑了0以下的数字
Function CustomRound(lngValue As Long)
Dim lngValueMin As Long
Dim lngValuePart As Long
Dim intNeg As Integer
If lngValue < 0 Then
lngValue = lngValue * -1
intNeg = -1
Else
intNeg = 1
End If
lngValueMin = lngValue - Right(lngValue, 2)
lngValuePart = Right(lngValue, 2)
If lngValuePart < 30 Then
CustomRound = lngValueMin * intNeg
Else
CustomRound = (lngValue + (100 - lngValuePart)) * intNeg
End If
End Function
1.29变为1,1.3变为2,…,1.99变为2?1.29变为1,1.3变为2,…,1.99变为2?这是我读课文后的想法。但是下面的评论改变了整个事情。不幸的是,这没有达到预期的效果。这是我在阅读课文后的想法。但是下面的评论改变了整个事情。不幸的是,这没有预期的结果。不幸的是,这没有预期的结果。我知道,事情要复杂得多。我将很快上传一个整数函数。不幸的是,这没有达到预期的效果。我知道,事情要复杂得多。我将很快上传一个整数函数。在我的函数尝试中,试图对所有内容进行四舍五入,例如0.3到1、3到10、30到100等,对不起。@VBASIC208无需担心,我感谢您的输入。我的函数尝试尝试对所有内容进行四舍五入,例如0.3到1、3到10、30到100等,对不起。@VBASIC208无需担心,我感谢您的输入