Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 450
  • Last Modified:

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
0
peanut1010
Asked:
peanut1010
  • 3
  • 2
  • 2
  • +1
1 Solution
 
MannSoftCommented:
You could use the FormatNumber() function.  I think maybe:

FormatNumber(TheNumber, 2, 0, 0, 0)
0
 
peanut1010Author Commented:
also if it is like this


00000012

should be 0.12
0
 
MannSoftCommented:
In that case, FormatNumber(TheNumber, 2, -1, 0, 0) should do it
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
peanut1010Author Commented:
it is putting the the numbers 1st and leaving the .0000


not

00000120

0.120

doing

120.00
0
 
GrahamSkanRetiredCommented:
Why not simply divide by 100?
0
 
peanut1010Author Commented:
because it would make it 1.2
divide by 1000 would still make it

120,000
0
 
GrahamSkanRetiredCommented:
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
0
 
rajsekarCommented:
try this

Val(MID("00001230",1,6))  & "." & Val(MID("00001230",7,2))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now