(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Decimal.Compare
public class Test
public Shared Sub Main
Dim D1, D2 As Decimal
D1 = 10
D2 = 5.7
Console.WriteLine(Decimal.rupare(D1, D2))
End Sub
End class
1
Decimal.Divide
public class Test
public Shared Sub Main
Dim D1, D2 As Decimal
D1 = 10
D2 = 5.7
Console.WriteLine(Decimal.Divide(D1, D2))
End Sub
End class
1.7543859649122807017543859649
Decimal.Floor
public class Test
public Shared Sub Main
Console.WriteLine(Decimal.Floor(5.7))
End Sub
End class
5
Decimal.GetBits
public class Test
public Shared Sub Main
Dim D1, D2 As Decimal
D1 = 10
D2 = 5.7
Console.WriteLine(Decimal.GetBits(3).GetValue(0))
End Sub
End class
3
Decmimal calculation
public class Test
public Shared Sub Main
Dim Dec1, Dec2 As Decimal
Dec1 = 100
Dec2 = 200
Dec1 = Dec1 + Dec2
Console.WriteLine(Dec1)
Dec1 = --Dec1
Console.WriteLine(Dec1)
Dec1 = ++Dec2
Console.WriteLine(Dec1)
End Sub
End class
300
300
200
Divide Decimal by double
Public Class Tester
Public Shared Sub Main
Dim result As New System.Text.StringBuilder
Dim maxDecimal As Decimal = Decimal.MaxValue
Dim sizeOfDecimal As Integer = Runtime.InteropServices.Marshal.SizeOf(maxDecimal.GetType)
result.Append("Memory size of a Decimal (bytes): ")
result.AppendLine(sizeOfDecimal)
result.Append("Maximum value of a Decimal: ")
result.AppendLine(maxDecimal)
result.Append("Divided by one million: ")
result.AppendLine(maxDecimal / 1000000D)
result.Append("1D / 3D: ")
result.AppendLine(1D / 3D)
Console.WriteLine(result.ToString())
End Sub
End Class
Memory size of a Decimal (bytes): 16
Maximum value of a Decimal: 79228162514264337593543950335
Divided by one million: 79228162514264337593543.950335
1D / 3D: 0.3333333333333333333333333333
Do calculation between Integer and Decimal
public class Test
public Shared Sub Main
Dim Meters As Integer
Dim Inches As Decimal
Meters = 23
Inches = Meters * 39.37
Console.WriteLine("Meters: " & Meters)
Meters = Meters + 1
Console.WriteLine("Meters: " & Meters)
Meters += 1
Console.WriteLine("Meters: " & Meters)
End Sub
End class
Meters: 23
Meters: 24
Meters: 25
MinValue and MaxValue of Decimal
public class Test
public Shared Sub Main
Dim dNum As Decimal
Console.WriteLine("Decimal: " & dNum.MinValue & " to " & dNum.MaxValue)
End Sub
End class
Decimal: -79228162514264337593543950335 to 79228162514264337593543950335