Wednesday, February 13, 2008

Flexible Decimal Places

The code below shown us how to make flexible decimal places. using cdbl, instr, len, and format function, we can make the flexible decimal places.

the idea is searching the position of "." and get the count of the rest number. after we get the number, we replace "0" with String Function as much as the count of the rest number.

here the code:


Private Sub Command1_Click()
Dim posisi As Integer
Dim a As Double
Dim jmldec As Integer
Dim jmlnol As String

a = CDbl(Text1.Text)
posisi = InStr(1, CStr(a), ".")
jmldec = Len(CStr(a)) - posisi

If posisi = 0 Then
jmlnol = "#"
Else
jmlnol = "#." + String(jmldec, "0")
End If

MsgBox Format(a, jmlnol)

End Sub


enjoy it...

0 comments:

Google

Microsoft News for ADO .NET:

Our Email Address:

blog.programming@gmail.com