Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
8th Edition
ISBN: 9781337102124
Author: Diane Zak
Publisher: Cengage Learning
Question
Book Icon
Chapter 3, Problem 2MQ6
Program Plan Intro

ToString Method:

The method ToString() is used to convert the number to string. All the numeric data types use ToString() method for this conversion. This method allows the user to format the value such as specifying the decimal places and adding special characters to the string which is to be displayed.

The ToString() methods formats the copy of value present in the numeric variable and then returns the result as string value.

Syntax:

numericVariableName.ToString(formatString)

  • The numericVariableName is the variable name.
  • The parameter formatString is used to format the variable’s value.
    • The formatString string should be in the form of “Axx”.
      • “A” represents the build format specifier and “xx” specifies the precision of the digits.
      • The format specifier can be in upper case letter or lower case letter.

The following table represents the list of format specifiers available in visual basic:

Format specifierDescription
C or c (Currency)It displays the string with dollar sign and included with a thousand separators. Negative values enclosed with parentheses.
N or n (Number)It displays the string with a thousand separators but not include a dollar sign. Negative values preceded by minus sign.

F or f

(Fixed-point)

It displays the string without thousand separator and dollar sign. Negative values preceded by minus sign.
P or p (Percent)It multiplies the number by 100 and displays the result with percentage sign and negative values preceded by minus sign.

Blurred answer
Students have asked these similar questions
Write a statement that displays the dblRate variable’s value in the lblRate.Text property. The value should contain a percent sign and no decimal places.
Write an expression that multiplies the value stored in the dblTotal variable by 15%.
Write a statement that displays the intQuantity variable’s value in the lblQuantity.Text property.

Chapter 3 Solutions

Programming with Microsoft Visual Basic 2017