VB.Net Tutorial/Data Type/Double
Версия от 16:40, 26 мая 2010; (обсуждение)
Содержание
- 1 Convert Double to Integer
- 2 Declare Double type variable and assign value
- 3 Define and loop through double value array
- 4 Define double and output its value
- 5 Double.IsNaN()
- 6 Double.IsNegativeInfinity()
- 7 Double.IsPositiveInfinity()
- 8 Get Epsilon from Double
- 9 Parse Double
- 10 Parse double value
- 11 Read Double value from Keyboard
Convert Double to Integer
Module Module1
Sub Main()
Dim dblValue As Double
Dim intValue As Integer
dblValue = 1.2345678
intValue = dblValue
Console.WriteLine(intValue)
End Sub
End Module
1
Declare Double type variable and assign value
Module Module1
Sub Main()
Dim EmployeeName As String
Dim EmployeePhoneNumber As String
Dim EmployeeSalary As Double
Dim NumberOfEmployees As Integer
EmployeeName = "James Bond"
EmployeePhoneNumber = "555-1212"
EmployeeSalary = 45.0
NumberOfEmployees = 1
Console.WriteLine("Number of employees: " & NumberOfEmployees)
Console.WriteLine("Employee name: " & EmployeeName)
Console.WriteLine("Employee phone number: " & EmployeePhoneNumber)
Console.WriteLine("Employee salary: " & EmployeeSalary)
End Sub
End Module
Number of employees: 1 Employee name: James Bond Employee phone number: 555-1212 Employee salary: 45
Define and loop through double value array
Module Tester
Sub Main()
Dim Values() As Integer = {100, 200, 300, 400, 500}
Dim MyValues(5) As Integer
Dim Prices() As Double = {25.5, 4.95, 33.4}
Dim I As Integer
For I = 0 To 4
Console.Write(Values(I) & " ")
Next
Console.WriteLine()
For I = 0 To Prices.GetUpperBound(0)
Console.Write(Prices(I) & " ")
Next
End Sub
End Module
100 200 300 400 500 25.5 4.95 33.4
Define double and output its value
public class Test
public Shared Sub Main
Dim I As Integer = 2
I *= 5
Console.WriteLine(I)
Dim D As Double = I / 3
Console.WriteLine(D)
End Sub
End class
10 3.33333333333333
Double.IsNaN()
Imports System
Module MyModule
Sub Main()
If (Double.IsNaN("1.2")) Then
Console.WriteLine("Not a Number.")
End If
End Sub
End Module
Double.IsNegativeInfinity()
Imports System
Module MyModule
Sub Main()
If (Double.IsNegativeInfinity("0.0000000000000001")) Then
Console.WriteLine("Negative infinity.")
End If
End Sub
End Module
Double.IsPositiveInfinity()
Imports System
Module MyModule
Sub Main()
If (Double.IsPositiveInfinity("999999999999999999999999999999999")) Then
Console.WriteLine("Positive infinity.")
End If
End Sub
End Module
Get Epsilon from Double
public class Test
public Shared Sub Main
Dim D As Double
D = 5
Console.WriteLine(D.Epsilon)
End Sub
End class
4.94065645841247E-324
Parse Double
Imports System
Module MyModule
Sub Main()
Dim num As Double = Double.Parse("12.12")
Dim denom As Double = Double.Parse("2.2")
Dim res As Double = num / denom
Console.WriteLine(res)
End Sub
End Module
5.50909090909091
Parse double value
Public Class Tester
Public Shared Sub Main
Dim doubleParse As Double = Double.Parse("3.1416")
Console.WriteLine(doubleParse)
End Sub
End Class
3.1416
Read Double value from Keyboard
Module Module1
Sub Main()
Dim Salary As Double
Console.Write("Salary: ")
Salary = Console.ReadLine()
Console.WriteLine(Salary)
End Sub
End Module
Salary: 123 123