Quitar decimales
Hola, gente desarrolladora, necesito un favor.
Me podrian decir como hago para quitar decimales a uin resultado por ejemplo 13,45567 quiro que quede 13,45
con solo dos decimales.
Nos vemos
Gracias >=>
Me podrian decir como hago para quitar decimales a uin resultado por ejemplo 13,45567 quiro que quede 13,45
con solo dos decimales.
Nos vemos
Gracias >=>
tal y como escribio baltasar, se debe tener cuidado son la funcion format que devuelve un string, y puede llevar a errores
mejor es int(num*100) / 100
mejor es int(num*100) / 100
Esta funcion te puede ayudar
Private Function ImprimeNumeros(Numero As Currency) As String
Dim strNumero As String
Dim strDec As String
Dim strX As String
Dim strR As String
Dim strP As String
Dim intPos As Integer
Dim intLong As Integer
Dim intCont As Integer
Dim intCantComas As Integer
strNumero = CStr(CCur(Numero))
If InStr(strNumero, ".") > 0 Then
strDec = Right(strNumero, 2)
If InStr(strDec, ".") > 0 Then
strNumero = strNumero & "0"
Else
strNumero = Mid(strNumero, 1, (InStr(strNumero, ".") + 2))
End If
Else
strNumero = strNumero & ".00"
End If
intLong = Len(strNumero) - 3
intCantComas = intLong / 3
strR = Right(strNumero, 3)
strNumero = Mid(strNumero, 1, Len(strNumero) - 3)
If Len(strNumero) > 3 Then
For intCont = 1 To intCantComas
intPos = intCont * 3
If Len(strNumero) > 3 Then
strP = Right(strNumero, 3)
strNumero = Mid(strNumero, 1, IIf(Len(strNumero) - 3 < 0, Len(strNumero), Len(strNumero) - 3))
strX = strNumero & "," & strP
End If
'strX = strX & "," & strP
Next
Else
strX = strNumero
End If
strX = strX & strR
If Mid(strX, 1, 1) = "," Then strX = Mid(strX, 2)
ImprimeNumeros = Format(strX, "@@@@@@@@@@@@@@@@@")
End Function
Hasta Luego
Private Function ImprimeNumeros(Numero As Currency) As String
Dim strNumero As String
Dim strDec As String
Dim strX As String
Dim strR As String
Dim strP As String
Dim intPos As Integer
Dim intLong As Integer
Dim intCont As Integer
Dim intCantComas As Integer
strNumero = CStr(CCur(Numero))
If InStr(strNumero, ".") > 0 Then
strDec = Right(strNumero, 2)
If InStr(strDec, ".") > 0 Then
strNumero = strNumero & "0"
Else
strNumero = Mid(strNumero, 1, (InStr(strNumero, ".") + 2))
End If
Else
strNumero = strNumero & ".00"
End If
intLong = Len(strNumero) - 3
intCantComas = intLong / 3
strR = Right(strNumero, 3)
strNumero = Mid(strNumero, 1, Len(strNumero) - 3)
If Len(strNumero) > 3 Then
For intCont = 1 To intCantComas
intPos = intCont * 3
If Len(strNumero) > 3 Then
strP = Right(strNumero, 3)
strNumero = Mid(strNumero, 1, IIf(Len(strNumero) - 3 < 0, Len(strNumero), Len(strNumero) - 3))
strX = strNumero & "," & strP
End If
'strX = strX & "," & strP
Next
Else
strX = strNumero
End If
strX = strX & strR
If Mid(strX, 1, 1) = "," Then strX = Mid(strX, 2)
ImprimeNumeros = Format(strX, "@@@@@@@@@@@@@@@@@")
End Function
Hasta Luego
para quitar decimales yo uso lo siguiente:
mTest = 13.45567
mTest1 = format(mTest, "0.00")
esto es si quieres solo dos decimales, pero si quieres tres agragas un cero, o sea "0.000" y asi sucesivamente.
Ciao
mTest = 13.45567
mTest1 = format(mTest, "0.00")
esto es si quieres solo dos decimales, pero si quieres tres agragas un cero, o sea "0.000" y asi sucesivamente.
Ciao