VB.Net/Language Basics/Double — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 12:42, 26 мая 2010

Assign result to both an integer and a double

Imports System
Public Class MainClass
    Shared Sub Main(ByVal args As String())
       Dim int1 As Integer = 12
       Dim int2 As Integer = 5
       Dim intAnswer As Integer
       Dim doubleAnswer As Double
       Console.WriteLine("{0} + {1} = {2}", int1, int2, int1 + int2)
       Console.WriteLine("{0} - {1} = {2}", int1, int2, int1 - int2)
       Console.WriteLine("{0} * {1} = {2}", int1, int2, int1 * int2)
       " integer division
       intAnswer = int1 \ int2
       doubleAnswer = int1 \ int2
       Console.WriteLine("{0} \ {1} = [integer] {2}  [double] {3}", _
           int1, int2, intAnswer, doubleAnswer)
       " division. Assign result to both an integer and a double
       " note, option strict must be off!
       intAnswer = int1 / int2
       doubleAnswer = int1 / int2
       Console.WriteLine("{0} / {1} = [integer] {2}  [double] {3}", _
           int1, int2, intAnswer, doubleAnswer)
    End Sub
End Class


Double number format: 0:n3

Imports System
Public Class MainClass
    Shared Sub Main()
        "Declare variable
        Dim dblNumber As Double
        "Set number, divide numbers, and display results
        dblNumber = 45.34
        dblNumber /= 4.333
        System.Console.WriteLine("Division test... " & dblNumber)
        System.Console.WriteLine("With formatting: " & String.Format("{0:n3}", dblNumber))
    End Sub
End Class


Double: Set number, divide numbers, and display results

Imports System
Public Class MainClass
    Shared Sub Main()
        "Declare variable
        Dim dblNumber As Double
        "Set number, divide numbers, and display results
        dblNumber = 45.34
        dblNumber /= 4.333
        System.Console.WriteLine("Division test... " & dblNumber)
    End Sub
End Class


Double: Set number, multiply numbers, and display results

Imports System
Public Class MainClass
    Shared Sub Main()
        "Declare variable
        Dim dblNumber As Double
        "Set number, multiply numbers, and display results
        dblNumber = 45.34
        dblNumber *= 4.333
        System.Console.WriteLine("Multiplication test... " & dblNumber)
    End Sub
End Class


Double value calculation

Imports System
Public Class MainClass
    Shared Sub Main()
        Dim dblRadiusSquared As Double
        Dim dblResult As Double
        Dim radius As Double
        
        radius = 10.01
        dblRadiusSquared = radius * radius
        dblResult = dblRadiusSquared * Math.PI
        System.Console.WriteLine(dblResult)
    End Sub
End Class