Videos

.

lunes, 25 de mayo de 2009

Truncar decimales - Visual Basic 6

Colocamos un CommandButton, una Label y un TextBox en el Formulario, tecleamos en el TextBox por ejemplo:


456.2345 y retorna 456.234
1234.12686461 y retorna 1234.126

Declaramos la funcion:

Public Function truncar(ByVal value As Double, ByVal escala As _
Integer) As Double
truncar = Int(value * 10 ^ escala) / 10 ^ escala
End Function
-----------------------------------------

Private Sub Command1_Click()
Label1.Caption = truncar(Val(Text1.Text), 3)'el tres indica el
'
numero de decimales que, queremos mostrar
End Sub

3 comentarios:

QUE GRANDE LOCO ME RE SIRVIO ESTA FUNCION, LO QUE SI NEGRO SACALE "VAL" XQ SINO TE TRUNCA EN EL ENTERO NADA MAS

Muchas gracias por compartir tus conocimientos con quienes los necesitamos.Tu aporte fue de mucha utilidad,gracias
Nelson

Super funcion muy buena gracias por el aporte

Insertar

Twitter Delicious Facebook Digg Stumbleupon Favorites More