Adding A Decimal In Visual Basic - Small Business
Có thể bạn quan tâm
Microsoft's Visual Basic programming language has variable types for three different kinds of numbers: integer, floating-point and decimal. Integer variables range from a short 2-byte format to a long 8-byte format. Floating point variables come in single and double precision. VB has a single decimal variable type that uses 16 bytes of memory and handles up to 29 significant digits.
Variable Declaration
As with any variable in Visual Basic, you declare a decimal type before you use it. To declare the variable, you use the "Dim" statement followed by the variable's name and the words "as decimal." For example, if you want to use the variable "Total_Sale" as a decimal calculation variable, you would use the following Visual Basic statement:
Advertisement
Article continues below this ad
Dim Total_Sale As Decimal
You can declare several decimal variables in the same Dim statement:
Dim Item_Cost, Item_Price, Total_Sale As Decimal
Use
Decimal variables are ideal for calculations requiring more than 16 digits of precision and for handling decimal calculations such as money. Visual Basic's floating point variables have a wider absolute range, up to 10^1023, but with precision limited to 16 digits. Also, because Visual Basic represents decimal variables internally as base-10 and not binary numbers, they resolve calculations involving decimal fractions more accurately than with floating point.
Advertisement
Article continues below this ad
More For You
Can You Save Equations in the iPhone Calculator?
Can You Save Equations in the iPhone Calculator?. Saving equations in a calculator can be...Spacing of Output in Java
Spacing of Output in Java. Java programs without a graphical user interface use a...Displaying Unicode With Visual Basic 6
Displaying Unicode With Visual Basic 6. Unicode lets you display extended characters in...What Is a Formula Prefix for a Worksheet?
What Is a Formula Prefix for a Worksheet?. A worksheet is a table in an electronic...How to Change Settings for Fractions to Decimals on the TI-89
How to Change Settings for Fractions to Decimals on the TI-89. The TI-89 is a graphing...Capacity
Decimal variables have an internal scaling counter that automatically keeps track of the decimal point. When dealing with integers, decimal variables range from -79E27 to +79E27. The smallest nonzero number a decimal variable holds is +/- 1E-28. Decimal variables hold up to 29 digits; every digit participates in calculations without rounding. For example, if you store the number "49,999,999,999,999,999,999,999" into a decimal variable and add 1, the result is "50,000,000,000,000,000,000,000." If you attempted this calculation with a floating-point variable, adding 1 would not increase the number as floating-point has insufficient precision.
Speed
In Visual Basic, integer arithmetic is fastest, followed by floating point and decimal. A computer's microprocessor has integer and floating point internal registers for calculations but not those for decimal. This means decimal calculations do not have the benefit of high-speed hardware and are performed entirely in software digit by digit. Though decimal variables have the capacity for constants as big as Avogadro's Number, 6.022E23, or as small as the mass of a proton, 1.67E-24 grams, floating-point numbers are better-suited to scientific calculations as they are much faster.
Advertisement
Article continues below this ad
References
- MSDN Library: Decimal Data Type
Chicago native John Papiewski has a physics degree and has been writing since 1991. He has contributed to "Foresight Update," a nanotechnology newsletter from the Foresight Institute. He also contributed to the book, "Nanotechnology: Molecular Speculations on Global Abundance."
Từ khóa » Visual Basic Double To Decimal
-
Convert Double To Decimal In
-
Decimal Data Type - Visual Basic - Microsoft Docs
-
Type Conversion Functions - Visual Basic - Microsoft Docs
-
VS 2019 Do You Use Decimal, Single, Or Double? - VBForums
-
- How To Convert Answer Into Two Decimal Point - Stack Overflow
-
How Do You Round A Number To Two Decimal Places C# VB.Net Asp.Net
-
Conversion From Double To Decimal Can Overflow : Data Type Convert
-
The Decimal Data Type - VB.NET
-
How To Declare Double Data Type In VBA? - WallStreetMojo
-
How Do You Decrease Decimals In Visual Basic? - Quora
-
Numeric Data Types In Visual Basic 2010 - YouTube
-
Variant/Decimal - VBA Data Types
-
Formatting Input And Output Strings For Multiple Countries - Keysight