TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET Double Type

Review the Double numeric type, which is 8 bytes long. Use double literals.
Double. A Double is 8 bytes. It is a value type. It stores numeric values that have a decimal place. It stores extremely small and extremely large numbers. Doubles are often used in VB.NET programs that also use the Math type.Math.Round
Example. Let us begin with this program. In Main, the program declares and assigns the Double number 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.

Note: The Double type stores signed numbers—even signed fractional numbers. We then evaluate some expressions that use this Double Dim.

Note 2: An expression context does not change the value stored in a variable. It evaluates to a new value on the evaluation stack.

And: These new values are passed to the Console.WriteLine Sub. Then they are forgotten.

VB.NET program that uses Double 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 Module Output 1.5 -1.5 True -0.5 System.Double -1.79769313486232E+308 1.79769313486232E+308 8.00004
We next examine the type of a Double variable—the full type has the composite name System.Double. The minimum value of a Double is very negative. And conversely the maximum value is highly positive.
The memory usage of a Double Dim is evaluated in the last segment of the VB.NET program. 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.

Result: We measure the memory again. This gives us the total memory used by one million Double elements.

Size: After division, a single Double is found to require 8 bytes of space. The excess bytes are for the array reference itself.

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.
VB.NET program that uses Single Module Module1 Sub Main() ' Use Single type. Dim number As Single = 10.35 Console.WriteLine(number) End Sub End Module Output 10.35
Summary. A Double is the size of two Integers put together. It is technically a Structure. With the extra bytes in this type, we gain a lot of features. It stores a decimal place and represents a much larger range of numbers than an Integer type.StructureInteger

Note: This extra storage space is critical in programs that do mathematical computations.

© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf