peanut1010
asked on
vb number format
I have a number that looks like this
00001230
what I need is a code that will format it like this
12.30
now sometimes the number will be
00231232
should be
2312.32
meaning always two on the right and 4 on the left
any ideas
00001230
what I need is a code that will format it like this
12.30
now sometimes the number will be
00231232
should be
2312.32
meaning always two on the right and 4 on the left
any ideas
ASKER
also if it is like this
00000012
should be 0.12
00000012
should be 0.12
In that case, FormatNumber(TheNumber, 2, -1, 0, 0) should do it
ASKER
it is putting the the numbers 1st and leaving the .0000
not
00000120
0.120
doing
120.00
not
00000120
0.120
doing
120.00
Why not simply divide by 100?
ASKER
because it would make it 1.2
divide by 1000 would still make it
120,000
divide by 1000 would still make it
120,000
Private Sub Command1_Click()
Dim Samples As Variant
Dim i As Integer
Samples = Array("00001230", "00231232", "00000012")
For i = 0 To UBound(Samples)
Debug.Print Format$(Samples(i) / 100, "0.00")
Next i
End Sub
Dim Samples As Variant
Dim i As Integer
Samples = Array("00001230", "00231232", "00000012")
For i = 0 To UBound(Samples)
Debug.Print Format$(Samples(i) / 100, "0.00")
Next i
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
FormatNumber(TheNumber, 2, 0, 0, 0)