本文整理汇总了VB.NET中System.Decimal结构体的典型用法代码示例。如果您正苦于以下问题:VB.NET Decimal结构体的具体用法?VB.NET Decimal怎么用?VB.NET Decimal使用的例子?那么, 这里精选的结构体代码示例或许可以为您提供帮助。
在下文中一共展示了Decimal结构体的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: PiggyBank
' Keeping my fortune in Decimals to avoid the round-off errors.
Class PiggyBank
Protected MyFortune As Decimal
Public Sub AddPenny()
MyFortune = [Decimal].Add(MyFortune, 0.01D)
End Sub
Public ReadOnly Property Capacity() As Decimal
Get
Return [Decimal].MaxValue
End Get
End Property
Public ReadOnly Property Dollars() As Decimal
Get
Return [Decimal].Floor(MyFortune)
End Get
End Property
Public ReadOnly Property Cents() As Decimal
Get
Return [Decimal].Subtract(MyFortune, [Decimal].Floor(MyFortune))
End Get
End Property
Public Overrides Function ToString() As String
Return MyFortune.ToString("C") + " in piggy bank"
End Function
End Class
示例2:
Dim dividend As Decimal = Decimal.One
Dim divisor As Decimal = 3
' The following displays 0.9999999999999999999999999999 to the console
Console.WriteLine(dividend/divisor * divisor)
示例3:
Dim dividend As Decimal = Decimal.One
Dim divisor As Decimal = 3
' The following displays 1.00 to the console
Console.WriteLine(Math.Round(dividend/divisor * divisor, 2))