Formatting Output

Every primitive data type (Short, Integer, Long, Decimal, Single, Double) has a ToString Method. The ToString method accepts an argument called the Format Specifier which specifies how the number is to be formatted.

 

lblOutput.Text = sngTicketPrice.ToString(“C”)

 

“C” – Currency, Displays dollar sign, commas and two decimal positions

“Cn” - Currency, Displays dollar sign, commas and n decimal positions

“N” – Displays commas and two decimal positions

“Nn” Displays commas and n decimal positions

 

lblOutput.Text = sngTicketPrice.ToString(“C2”)

 

“F” – Will always display at least 1 digit to the left of the decimal and 2 to the right.

“P” – Displays as percent

 

You can also create your own custom format string

lblOutput.Text = sngTicketPrice.ToString(“###,###.00”)