-- toentero, a que no lo limite la cantdad del string

This commit is contained in:
2021-07-17 10:45:45 -07:00
parent aaad4f7b16
commit 53504a7585

View File

@@ -580,11 +580,12 @@ Namespace Extensiones
End Function
<Runtime.CompilerServices.Extension()>
Public Function ToEntero(Obj As Object) As Integer
If Obj IsNot Nothing AndAlso Obj.ToString.Trim <> "" AndAlso Obj.ToString.TrimStart("0"c).Length < 10 Then ' restriccion menor a 10, se quitan ceros a la izquiera primero, porque provoca desbordamiento si pasa mas de una cantidad,Holds signed 32-bit (4-byte) integers that range in value from -2,147,483,648 through 2,147,483,647.
Public Function ToEntero(Obj As Object) As Integer
If Obj IsNot Nothing AndAlso Obj.ToString.Trim <> "" Then ' porque provoca desbordamiento si pasa mas de una cantidad,Holds signed 32-bit (4-byte) integers that range in value from -2,147,483,648 through 2,147,483,647.
Dim Str As String = HttpUtility.HtmlDecode(Obj.ToString.Trim).Replace(","c, "")
Return If(IsNumeric(Str), CInt(Str), 0)
'si es numerico, si no excede a 10 caracteres, convierte el valor a entero, si excede de 10 digitos, verifica la cantidad permitida. si es menor a su dato, se valida
Return If(IsNumeric(Str), If(Str.Length < 10, CInt(Str), If(CDec(Str) < Int32.MaxValue, CInt(Str), 0)), 0)
Else
Return 0
End If