How to Right Justify Numbers Using Format$Last reviewed: June 21, 1995Article ID: Q95945 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0
SUMMARYNOTE: The technique described in this article works only with monospace fonts like Courier New, not proportional fonts like Times New Roman. Use the following two-step process to right justify numbers in a string by using the format$ function:
Sub Form_Click () Print "|" + Format$(Format$(1.5, "$##0.00"), "@@@@@@@") + "|" Print "|" + Format$(Format$(12.5, "$##0.00"), "@@@@@@@") + "|" Print "|" + Format$(Format$(123.5, "$##0.00"), "@@@@@@@") + "|" End SubHere is the output:
| $1.50| | $12.50| |$123.50| MORE INFORMATIONYou can automatically generate the @ format string by using Len and String$ as in this example:
Function rFormat (value As Variant, fmt As String) As Variant rFormat = Format(Format(value, fmt), String$(Len(fmt), "@")) End Function |
Additional reference words: 2.00 3.00 align alignment right-justify
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |