Double
In VB.NET a Double
is 8 bytes—the size of 2 Integers. It is a value type. The Double
stores numeric values that have a decimal place.
Double
stores extremely small and large numbers. Doubles are often used in VB.NET programs that also use the Math type.
In Main
, the program assigns a Double
to the value 1.5. We then display this to the Console
. Next, the same variable (a location in memory) is assigned the value -1.5.
Double
type stores signed numbers—even signed fractional numbers. We then evaluate some expressions that use this Double
Dim
.Console.WriteLine
Sub
. Then they are forgotten.Double
is a big negative value. And conversely the maximum value is highly positive.Module Module1 Sub Main() ' Use Double Dim. Dim number As Double = 1.5 Console.WriteLine(number) ' Negative Double. number = -1.5 Console.WriteLine(number) ' Evaluate expressions. Console.WriteLine(number = -1.5) Console.WriteLine(number + 1) Console.WriteLine(number.GetType()) ' Min and Max. Console.WriteLine(Double.MinValue) Console.WriteLine(Double.MaxValue) ' Memory usage per Double. Dim b1 As Long = GC.GetTotalMemory(False) Dim array(1000 * 1000) As Double array(0) = 1 Dim b2 As Long = GC.GetTotalMemory(False) Console.WriteLine((b2 - b1) / (1000 * 1000)) End Sub End Module1.5 -1.5 True -0.5 System.Double -1.79769313486232E+308 1.79769313486232E+308 8.00004
We use the GC type to figure out how much memory the program is using. Then we allocate an array of one million Double
elements.
Double
elements.Double
is found to require 8 bytes of space. The excess bytes are for the array reference itself.8 bytes
Single
A Single
is a floating-point number like Double
, but with less precision. It has half the bytes—so it requires 4 bytes. This simple program shows the Single
keyword.
Module Module1 Sub Main() ' Use Single type. Dim number As Single = 10.35 Console.WriteLine(number) End Sub End Module10.35
A Double
is the size of two Integers put together. It is technically a Structure
. It stores a decimal place and represents a much larger range of numbers than an Integer type.