Monday, July 28, 2008

How to format string to currency?

Use:
Public Function FormatCurrency(ByVal Expression As Object, Optional ByVal NumDigitsAfterDecimal As Integer = -1, Optional ByVal IncludeLeadingDigit As Microsoft.VisualBasic.TriState = UseDefault, Optional ByVal UseParensForNegativeNumbers As Microsoft.VisualBasic.TriState = UseDefault, Optional ByVal GroupDigits As Microsoft.VisualBasic.TriState = UseDefault) As String

Member of Microsoft.VisualBasic.Strings
-------------------------------
Examples:
Messagebox.show(Strings.FormatCurrency(str))

If the string is 7.75 the message box would show $7.75

Messagebox.show(Strings.FormatCurrency(str,4))

If the string is 7.75 the message box would show $7.7500

MessageBox.Show(Strings.FormatCurrency(str, 4, TriState.False))
If the string is 0.75 the message box would show $.7500

MessageBox.Show(Strings.FormatCurrency(str, 4, TriState.True))
If the string is 0.75 the message box would show $0.7500

No comments: