• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

VB.NET Double结构体代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了VB.NET中System.Double结构体的典型用法代码示例。如果您正苦于以下问题:VB.NET Double结构体的具体用法?VB.NET Double怎么用?VB.NET Double使用的例子?那么恭喜您, 这里精选的结构体代码示例或许可以为您提供帮助。



在下文中一共展示了Double结构体的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。

示例1: Temperature

' Temperature class stores the value as Double
' and delegates most of the functionality 
' to the Double implementation.
Public Class Temperature
    Implements IComparable, IFormattable

    Public Overloads Function CompareTo(ByVal obj As Object) As Integer _
        Implements IComparable.CompareTo

        If TypeOf obj Is Temperature Then
            Dim temp As Temperature = CType(obj, Temperature)

            Return m_value.CompareTo(temp.m_value)
        End If

        Throw New ArgumentException("object is not a Temperature")
    End Function

    Public Overloads Function ToString(ByVal format As String, ByVal provider As IFormatProvider) As String _
        Implements IFormattable.ToString

        If Not (format Is Nothing) Then
            If format.Equals("F") Then
                Return [String].Format("{0}'F", Me.Value.ToString())
            End If
            If format.Equals("C") Then
                Return [String].Format("{0}'C", Me.Celsius.ToString())
            End If
        End If

        Return m_value.ToString(format, provider)
    End Function

    ' Parses the temperature from a string in form
    ' [ws][sign]digits['F|'C][ws]
    Public Shared Function Parse(ByVal s As String, ByVal styles As NumberStyles, ByVal provider As IFormatProvider) As Temperature
        Dim temp As New Temperature()

        If s.TrimEnd(Nothing).EndsWith("'F") Then
            temp.Value = Double.Parse(s.Remove(s.LastIndexOf("'"c), 2), styles, provider)
        Else
            If s.TrimEnd(Nothing).EndsWith("'C") Then
                temp.Celsius = Double.Parse(s.Remove(s.LastIndexOf("'"c), 2), styles, provider)
            Else
                temp.Value = Double.Parse(s, styles, provider)
            End If
        End If
        Return temp
    End Function

    ' The value holder
    Protected m_value As Double

    Public Property Value() As Double
        Get
            Return m_value
        End Get
        Set(ByVal Value As Double)
            m_value = Value
        End Set
    End Property

    Public Property Celsius() As Double
        Get
            Return (m_value - 32) / 1.8
        End Get
        Set(ByVal Value As Double)
            m_value = Value * 1.8 + 32
        End Set
    End Property
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:71,代码来源:Double


示例2: Example

Module Example
   Public Sub Main()
      Dim value As Double = .1
      Dim result1 As Double = value * 10
      Dim result2 As Double
      For ctr As Integer = 1 To 10
         result2 += value
      Next
      Console.WriteLine(".1 * 10:           {0:R}", result1)
      Console.WriteLine(".1 Added 10 times: {0:R}", result2)
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:12,代码来源:Double

输出:

.1 * 10:           1
.1 Added 10 times: 0.99999999999999989


示例3: Example

Module Example
   Public Sub Main()
      Dim value As Double = 123456789012.34567
      Dim additional As Double = Double.Epsilon * 1e15
      Console.WriteLine("{0} + {1} = {2}", value, additional, 
                                           value + additional)
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:8,代码来源:Double

输出:

123456789012.346 + 4.94065645841247E-309 = 123456789012.346


示例4: Example

Module Example
   Public Sub Main()
      Dim values() As Double = { 10.0, 2.88, 2.88, 2.88, 9.0 }
      Dim result As Double = 27.64
      Dim total As Double
      For Each value In values
         total += value
      Next
      If total.Equals(result) Then
         Console.WriteLine("The sum of the values equals the total.")
      Else
         Console.WriteLine("The sum of the values ({0}) does not equal the total ({1}).",
                           total, result) 
      End If     
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:16,代码来源:Double

输出:

The sum of the values (36.64) does not equal the total (36.64).   

If the index items in the Console.WriteLine statement are changed to {0:R},
the example displays the following output:
The sum of the values (27.639999999999997) does not equal the total (27.64).


示例5: Example

' 导入命名空间
Imports System.IO

Module Example
   Public Sub Main()
      Dim sw As New StreamWriter(".\Doubles.dat")
      Dim values() As Double = { 2.2/1.01, 1.0/3, Math.PI }
      For ctr As Integer = 0 To values.Length - 1
         sw.Write(values(ctr).ToString())
         If ctr <> values.Length - 1 Then sw.Write("|")
      Next      
      sw.Close()
      
      Dim restoredValues(values.Length - 1) As Double
      Dim sr As New StreamReader(".\Doubles.dat")
      Dim temp As String = sr.ReadToEnd()
      Dim tempStrings() As String = temp.Split("|"c)
      For ctr As Integer = 0 To tempStrings.Length - 1
         restoredValues(ctr) = Double.Parse(tempStrings(ctr))   
      Next 

      For ctr As Integer = 0 To values.Length - 1
         Console.WriteLine("{0} {2} {1}", values(ctr), 
                           restoredValues(ctr),
                           If(values(ctr).Equals(restoredValues(ctr)), "=", "<>"))
      Next
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:28,代码来源:Double

输出:

2.17821782178218 <> 2.17821782178218
0.333333333333333 <> 0.333333333333333
3.14159265358979 <> 3.14159265358979


示例6: Example

' 导入命名空间
Imports System.IO

Module Example
   Public Sub Main()
      Dim sw As New StreamWriter(".\Doubles.dat")
      Dim values() As Double = { 2.2/1.01, 1.0/3, Math.PI }
      For ctr As Integer = 0 To values.Length - 1
         sw.Write("{0:G17}{1}", values(ctr), 
                  If(ctr < values.Length - 1, "|", ""))
      Next      
      sw.Close()
      
      Dim restoredValues(values.Length - 1) As Double
      Dim sr As New StreamReader(".\Doubles.dat")
      Dim temp As String = sr.ReadToEnd()
      Dim tempStrings() As String = temp.Split("|"c)
      For ctr As Integer = 0 To tempStrings.Length - 1
         restoredValues(ctr) = Double.Parse(tempStrings(ctr))   
      Next 

      For ctr As Integer = 0 To values.Length - 1
         Console.WriteLine("{0} {2} {1}", values(ctr), 
                           restoredValues(ctr),
                           If(values(ctr).Equals(restoredValues(ctr)), "=", "<>"))
      Next
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:28,代码来源:Double

输出:

2.17821782178218 = 2.17821782178218
0.333333333333333 = 0.333333333333333
3.14159265358979 = 3.14159265358979


示例7: Example

Module Example
   Public Sub Main()
      Dim value1 As Double = 1/3
      Dim sValue2 As Single = 1/3
      Dim value2 As Double = CDbl(sValue2)
      Console.WriteLine("{0} = {1}: {2}", value1, value2, value1.Equals(value2))
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:8,代码来源:Double

输出:

0.33333333333333331 = 0.3333333432674408: False


示例8:

Dim value As Double = -4.42330604244772E-305

Dim fromLiteral As Double = -4.42330604244772E-305
Dim fromVariable As Double = value
Dim fromParse As Double = Double.Parse("-4.42330604244772E-305")

Console.WriteLine("Double value from literal: {0,29:R}", fromLiteral)
Console.WriteLine("Double value from variable: {0,28:R}", fromVariable)
Console.WriteLine("Double value from Parse method: {0,24:R}", fromParse)      
' On 32-bit versions of the .NET Framework, the output is:
'    Double value from literal:        -4.42330604244772E-305
'    Double value from variable:       -4.42330604244772E-305
'    Double value from Parse method:   -4.42330604244772E-305
'
' On other versions of the .NET Framework, the output is:
'    Double value from literal:        -4.4233060424477198E-305
'    Double value from variable:       -4.4233060424477198E-305
'    Double value from Parse method:     -4.42330604244772E-305
开发者ID:VB.NET开发者,项目名称:System,代码行数:18,代码来源:Double


示例9: Example

Module Example
   Public Sub Main()
      Dim value1 As Double = .333333333333333
      Dim value2 As Double = 1/3
      Console.WriteLine("{0:R} = {1:R}: {2}", value1, value2, value1.Equals(value2))
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:7,代码来源:Double

输出:

0.333333333333333 = 0.33333333333333331: False


示例10: Example

Module Example
   Public Sub Main()
      Dim value1 As Double = 100.10142
      value1 = Math.Sqrt(Math.Pow(value1, 2))
      Dim value2 As Double = Math.Pow(value1 * 3.51, 2)
      value2 = Math.Sqrt(value2) / 3.51
      Console.WriteLine("{0} = {1}: {2}", 
                        value1, value2, value1.Equals(value2)) 
      Console.WriteLine()
      Console.WriteLine("{0:R} = {1:R}", value1, value2) 
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:12,代码来源:Double

输出:

100.10142 = 100.10142: False

100.10142 = 100.10141999999999


示例11: Example

Module Example
   Public Sub Main()
      Dim value1 As Double = .333333333333333
      Dim value2 As Double = 1/3
      Dim precision As Integer = 7
      value1 = Math.Round(value1, precision)
      value2 = Math.Round(value2, precision)
      Console.WriteLine("{0:R} = {1:R}: {2}", value1, value2, value1.Equals(value2))
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:10,代码来源:Double

输出:

0.3333333 = 0.3333333: True


示例12: Example

Module Example
   Public Sub Main()
      Dim one1 As Double = .1 * 10
      Dim one2 As Double = 0
      For ctr As Integer = 1 To 10
         one2 += .1
      Next
      Console.WriteLine("{0:R} = {1:R}: {2}", one1, one2, one1.Equals(one2))
      Console.WriteLine("{0:R} is approximately equal to {1:R}: {2}", 
                        one1, one2, 
                        IsApproximatelyEqual(one1, one2, .000000001))   
   End Sub

   Function IsApproximatelyEqual(value1 As Double, value2 As Double, 
                                 epsilon As Double) As Boolean
      ' If they are equal anyway, just return True.
      If value1.Equals(value2) Then Return True
      
      ' Handle NaN, Infinity.
      If Double.IsInfinity(value1) Or Double.IsNaN(value1) Then
         Return value1.Equals(value2)
      Else If Double.IsInfinity(value2) Or Double.IsNaN(value2)
         Return value1.Equals(value2)
      End If
      
      ' Handle zero to avoid division by zero
      Dim divisor As Double = Math.Max(value1, value2)
      If divisor.Equals(0) Then
         divisor = Math.Min(value1, value2)
      End If 
      
      Return Math.Abs((value1 - value2) / divisor) <= epsilon           
   End Function
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:34,代码来源:Double

输出:

1 = 0.99999999999999989: False
1 is approximately equal to 0.99999999999999989: True


示例13: Example

Module Example
   Public Sub Main()
      Dim value1 As Double = 1.1632875981534209e-225
      Dim value2 As Double = 9.1642346778e-175
      Dim result As Double = value1 * value2
      Console.WriteLine("{0} * {1} = {2}", value1, value2, result)
      Console.WriteLine("{0} = 0: {1}", result, result.Equals(0.0))
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:9,代码来源:Double

输出:

1.16328759815342E-225 * 9.1642346778E-175 = 0
0 = 0: True


示例14: Example

Module Example
   Public Sub Main()
      Dim value1 As Double = 4.565e153
      Dim value2 As Double = 6.9375e172
      Dim result As Double = value1 * value2
      Console.WriteLine("PositiveInfinity: {0}", 
                         Double.IsPositiveInfinity(result))
      Console.WriteLine("NegativeInfinity: {0}", 
                        Double.IsNegativeInfinity(result))
      Console.WriteLine()                  
      value1 = -value1
      result = value1 * value2
      Console.WriteLine("PositiveInfinity: {0}", 
                         Double.IsPositiveInfinity(result))
      Console.WriteLine("NegativeInfinity: {0}", 
                        Double.IsNegativeInfinity(result))
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:18,代码来源:Double

输出:

PositiveInfinity: True
NegativeInfinity: False

PositiveInfinity: False
NegativeInfinity: True


示例15: Example

Module Example
   Public Sub Main()
      Dim values() As Object = { Byte.MinValue, Byte.MaxValue, Decimal.MinValue,
                                 Decimal.MaxValue, Int16.MinValue, Int16.MaxValue,
                                 Int32.MinValue, Int32.MaxValue, Int64.MinValue,
                                 Int64.MaxValue, SByte.MinValue, SByte.MaxValue,
                                 Single.MinValue, Single.MaxValue, UInt16.MinValue,
                                 UInt16.MaxValue, UInt32.MinValue, UInt32.MaxValue,
                                 UInt64.MinValue, UInt64.MaxValue }
      Dim dblValue As Double
      For Each value In values
         dblValue = value
         Console.WriteLine("{0} ({1}) --> {2:R} ({3})",
                           value, value.GetType().Name,
                           dblValue, dblValue.GetType().Name)
      Next
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:18,代码来源:Double

输出:

0 (Byte) --> 0 (Double)
255 (Byte) --> 255 (Double)
-79228162514264337593543950335 (Decimal) --> -7.9228162514264338E+28 (Double)
79228162514264337593543950335 (Decimal) --> 7.9228162514264338E+28 (Double)
-32768 (Int16) --> -32768 (Double)
32767 (Int16) --> 32767 (Double)
-2147483648 (Int32) --> -2147483648 (Double)
2147483647 (Int32) --> 2147483647 (Double)
-9223372036854775808 (Int64) --> -9.2233720368547758E+18 (Double)
9223372036854775807 (Int64) --> 9.2233720368547758E+18 (Double)
-128 (SByte) --> -128 (Double)
127 (SByte) --> 127 (Double)
-3.402823E+38 (Single) --> -3.4028234663852886E+38 (Double)
3.402823E+38 (Single) --> 3.4028234663852886E+38 (Double)
0 (UInt16) --> 0 (Double)
65535 (UInt16) --> 65535 (Double)
0 (UInt32) --> 0 (Double)
4294967295 (UInt32) --> 4294967295 (Double)
0 (UInt64) --> 0 (Double)
18446744073709551615 (UInt64) --> 1.8446744073709552E+19 (Double)


示例16: Example

Module Example
   Public Sub Main()
      Dim values() As Double = { Double.MinValue, -67890.1234, -12345.6789,
                                 12345.6789, 67890.1234, Double.MaxValue,
                                 Double.NaN, Double.PositiveInfinity,
                                 Double.NegativeInfinity }
      For Each value In values
         Try
             Dim lValue As Int64 = CLng(value)
             Console.WriteLine("{0} ({1}) --> {2} (0x{2:X16}) ({3})",
                               value, value.GetType().Name,
                               lValue, lValue.GetType().Name)
         Catch e As OverflowException
            Console.WriteLine("Unable to convert {0} to Int64.", value)
         End Try
         Try
             Dim ulValue As UInt64 = CULng(value)
             Console.WriteLine("{0} ({1}) --> {2} (0x{2:X16}) ({3})",
                               value, value.GetType().Name,
                               ulValue, ulValue.GetType().Name)
         Catch e As OverflowException
            Console.WriteLine("Unable to convert {0} to UInt64.", value)
         End Try
         Try
             Dim dValue As Decimal = CDec(value)
             Console.WriteLine("{0} ({1}) --> {2} ({3})",
                               value, value.GetType().Name,
                               dValue, dValue.GetType().Name)
         Catch e As OverflowException
            Console.WriteLine("Unable to convert {0} to Decimal.", value)
         End Try
         Try
             Dim sValue As Single = CSng(value)
             Console.WriteLine("{0} ({1}) --> {2} ({3})",
                               value, value.GetType().Name,
                               sValue, sValue.GetType().Name)
         Catch e As OverflowException
            Console.WriteLine("Unable to convert {0} to Single.", value)
         End Try
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output for conversions performed
' in a checked context:
'       Unable to convert -1.79769313486232E+308 to Int64.
'       Unable to convert -1.79769313486232E+308 to UInt64.
'       Unable to convert -1.79769313486232E+308 to Decimal.
'       -1.79769313486232E+308 (Double) --> -Infinity (Single)
'
'       -67890.1234 (Double) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
'       Unable to convert -67890.1234 to UInt64.
'       -67890.1234 (Double) --> -67890.1234 (Decimal)
'       -67890.1234 (Double) --> -67890.13 (Single)
'
'       -12345.6789 (Double) --> -12346 (0xFFFFFFFFFFFFCFC6) (Int64)
'       Unable to convert -12345.6789 to UInt64.
'       -12345.6789 (Double) --> -12345.6789 (Decimal)
'       -12345.6789 (Double) --> -12345.68 (Single)
'
'       12345.6789 (Double) --> 12346 (0x000000000000303A) (Int64)
'       12345.6789 (Double) --> 12346 (0x000000000000303A) (UInt64)
'       12345.6789 (Double) --> 12345.6789 (Decimal)
'       12345.6789 (Double) --> 12345.68 (Single)
'
'       67890.1234 (Double) --> 67890 (0x0000000000010932) (Int64)
'       67890.1234 (Double) --> 67890 (0x0000000000010932) (UInt64)
'       67890.1234 (Double) --> 67890.1234 (Decimal)
'       67890.1234 (Double) --> 67890.13 (Single)
'
'       Unable to convert 1.79769313486232E+308 to Int64.
'       Unable to convert 1.79769313486232E+308 to UInt64.
'       Unable to convert 1.79769313486232E+308 to Decimal.
'       1.79769313486232E+308 (Double) --> Infinity (Single)
'
'       Unable to convert NaN to Int64.
'       Unable to convert NaN to UInt64.
'       Unable to convert NaN to Decimal.
'       NaN (Double) --> NaN (Single)
'
'       Unable to convert Infinity to Int64.
'       Unable to convert Infinity to UInt64.
'       Unable to convert Infinity to Decimal.
'       Infinity (Double) --> Infinity (Single)
'
'       Unable to convert -Infinity to Int64.
'       Unable to convert -Infinity to UInt64.
'       Unable to convert -Infinity to Decimal.
'       -Infinity (Double) --> -Infinity (Single)
' The example displays the following output for conversions performed
' in an unchecked context:
'       -1.79769313486232E+308 (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
'       -1.79769313486232E+308 (Double) --> 9223372036854775808 (0x8000000000000000) (UInt64)
'       Unable to convert -1.79769313486232E+308 to Decimal.
'       -1.79769313486232E+308 (Double) --> -Infinity (Single)
'
'       -67890.1234 (Double) --> -67890 (0xFFFFFFFFFFFEF6CE) (Int64)
'       -67890.1234 (Double) --> 18446744073709483726 (0xFFFFFFFFFFFEF6CE) (UInt64)
'       -67890.1234 (Double) --> -67890.1234 (Decimal)
'       -67890.1234 (Double) --> -67890.13 (Single)
'
'       -12345.6789 (Double) --> -12346 (0xFFFFFFFFFFFFCFC6) (Int64)
'       -12345.6789 (Double) --> 18446744073709539270 (0xFFFFFFFFFFFFCFC6) (UInt64)
'       -12345.6789 (Double) --> -12345.6789 (Decimal)
'       -12345.6789 (Double) --> -12345.68 (Single)
'
'       12345.6789 (Double) --> 12346 (0x000000000000303A) (Int64)
'       12345.6789 (Double) --> 12346 (0x000000000000303A) (UInt64)
'       12345.6789 (Double) --> 12345.6789 (Decimal)
'       12345.6789 (Double) --> 12345.68 (Single)
'
'       67890.1234 (Double) --> 67890 (0x0000000000010932) (Int64)
'       67890.1234 (Double) --> 67890 (0x0000000000010932) (UInt64)
'       67890.1234 (Double) --> 67890.1234 (Decimal)
'       67890.1234 (Double) --> 67890.13 (Single)
'
'       1.79769313486232E+308 (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
'       1.79769313486232E+308 (Double) --> 0 (0x0000000000000000) (UInt64)
'       Unable to convert 1.79769313486232E+308 to Decimal.
'       1.79769313486232E+308 (Double) --> Infinity (Single)
'
'       NaN (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
'       NaN (Double) --> 0 (0x0000000000000000) (UInt64)
'       Unable to convert NaN to Decimal.
'       NaN (Double) --> NaN (Single)
'
'       Infinity (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
'       Infinity (Double) --> 0 (0x0000000000000000) (UInt64)
'       Unable to convert Infinity to Decimal.
'       Infinity (Double) --> Infinity (Single)
'
'       -Infinity (Double) --> -9223372036854775808 (0x8000000000000000) (Int64)
'       -Infinity (Double) --> 9223372036854775808 (0x8000000000000000) (UInt64)
'       Unable to convert -Infinity to Decimal.
'       -Infinity (Double) --> -Infinity (Single)
开发者ID:VB.NET开发者,项目名称:System,代码行数:135,代码来源:Double



注:本文中的System.Double结构体示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET IntPtr结构体代码示例发布时间:2022-05-24
下一篇:
VB.NET TypeCode枚举代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap