I'm trying to make something like a str_pad
function in VBA, returning leading zeros ahead monetary values.
For example, if I want to pad it with 6 digits:
Input:
$ 423,67
Output:
000423
So far, it can add those leading zeros, but I cant figure out a way to implement it when it doens't have decimals:
Input:
$ 423,00
Current output:
000423
Desired output:
042300
Since the user usually doesn't include zeros after the comma, my code should be able to put them on the output.
Code:
Function str_pad(text As Variant, totalLength As Integer, padCharacter As String) As String
If totalLength > Len(CStr(text)) Then
'str_pad = String(totalLength - Len(CStr(text)), padCharacter) & CStr(text)
Else
str_pad = text
End If
End Function