Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to right justify a number

Status
Not open for further replies.

tfstom

Programmer
Joined
Sep 28, 2002
Messages
190
Location
US
How do I right justify a number.

I can't seem to get it to work. If I have the following format: Format(Number, "###0.0") and numbers
.1, 100.1 and 10

I end up with
0.1
100.1
10.0
But I want to end up with:
0.1
100.1
10.0

How do I do this?

Thanks,

Tom.
 

[tt]
Text1.Alignment = vbAlignRight
[/tt]

Have you read FAQ222-2244 item 15 yet?

Good Luck

 
No, this is not an object.

It is a variable that I am displaying to a text box. Since it is not right justifying, all the numbers that follow get out of line if the number is not exactly 6 characters long.

Thanks,

Tom
 
Ok - two ideas...

First of all, try format(dbl,"00000.0") where dbl is your number.

Failing that - try (for a 6 character field)

msgbox right((string(6,"0")+cstr(dbl),6)

mmilan

 
Public Function RightAlign(strSource As String, ByVal CharCount As Long) As String
If CharCount < Len(strSource) Then CharCount = Len(strSource)
RightAlign = Space(CharCount)
RSet RightAlign = strSource
End Function
 
Or

Dim Test As String
Dim Number As Double
Number = 0.1
Test = Format$(Format(Number, "###0.0"), "@@@@@@")
MsgBox Test

Swi
 
Now all you need to do is some timings to see which option is fastest...
 
Replace "String(6,"0")" with "string(6," ")" in my second idea - just read your question a little more carefully...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top