50 likes | 178 Views
Ch 3 Type Conversion . Yonglei Tao. Method TryParse (). Convert a string to a numeric data type Dim decSales As Decimal Decimal.TryParse ( txtSales.Text , decSales ) Dim intNum As Integer Integer.TryParse ( txtNum.Text , intNum ). Class Convert.
E N D
Ch 3 Type Conversion Yonglei Tao
Method TryParse() • Convert a string to a numeric data type Dim decSales As Decimal Decimal.TryParse ( txtSales.Text, decSales ) Dim intNum As Integer Integer.TryParse( txtNum.Text, intNum )
Class Convert • Provides methods to convert a value from one data type to another decTax = Convert.ToDecimal ( dblRate ) * decTotal lblAvg.Text = Convert.ToString ( intAvgScore )
Method ToString() • Available to each variable of a numeric type lbl.Commission.Text = intCommission.ToString ( “C2” ) lblRate.Text = dblRate.ToString (“P0”)