Question Currency format HELP

mrblob

New member
Joined
Oct 15, 2010
Messages
2
Programming Experience
Beginner
Hey, I'm very new to vb.net and i was wondering how to make a variable called amount and display it in a currency format using syntax ?

I hope i explained this okay
 
You can choose whatever numeric type you think is appropriate. For whole numbers only you would use Integer. For decimal values you would use Double. For decimal values that will be used in calculations that require high precision you would use Decimal. To display a numeric value as currency using the current system regional settings, you use the appropriate standard format string and optionally specify a number of decimal digits:
VB.NET:
Dim int As Integer = 12
Dim dbl As Double = 34.56
Dim dec As Decimal = 78.9

MessageBox.Show(int.ToString("c"))
MessageBox.Show(dbl.ToString("c"))
MessageBox.Show(dec.ToString("c"))

MessageBox.Show(int.ToString("c0"))
MessageBox.Show(dbl.ToString("c0"))
MessageBox.Show(dec.ToString("c0"))

MessageBox.Show(String.Format("Amount: {0:c}", int))
MessageBox.Show(String.Format("Amount: {0:c}", dbl))
MessageBox.Show(String.Format("Amount: {0:c}", dec))

MessageBox.Show(String.Format("Amount: {0:c0}", int))
MessageBox.Show(String.Format("Amount: {0:c0}", dbl))
MessageBox.Show(String.Format("Amount: {0:c0}", dec))
If you need to use a specific culture that may not be the system default, let us know and we can show you how to handle that.
 
Back
Top