Search code examples
vb6formattingformatnumber-formatting

Format String with fixed length with leading spaces


I need to format a string for a fixed length. I tried to use this format function from msdn

Dim i as Decimal
i = 123,12
MsgBox(Format(i,"######.##"))

Output 123.12

But the Output I want is with the leading spaces. ( the underscore should be a space char )

Output ___123.12


Solution

  • Add the spaces in the format syntax like this and it'll work.

    Format(12.323, "  ##.##")