Thursday, September 29, 2016

Data Types

Data Types

String
Strings can be a made up of a range of characters, this can include spaces it can also include other characters such as exclamation marks and question marks. Numbers can also be used in a string but it will only be seen as a character and would not be able to do mathematical sums if you added the strings it would just place the numbers side by side. Stings are usually placed in between single quotation marks.

Char
A character is a single letter this takes less space to store than a string, this would be good if it was a low memory based program that being said it is only able to store one character as oppose to a full word or a string.

Integer
An integer is commonly used feature within many programming languages there is a limit to using integers in the fact that they have to be a whole number and this means that it is unable to contain a decimal this would mean it is very restrictive if trying to add or subtract decimal numbers.

Float
A float is a number that is able to contain a decimal point this would be a lot more beneficial for storing decimals this would be very preferable when dealing numbers that leave a decimal number.

Boolean
The Boolean data type is a yes and a no function that would output true or false dependent on whether the criteria had been met.

Currency
Currency is also a data type; this allows the user to do financial calculations a lot more precisely it will also allow the use of currency signs such as the dollar sign and the pound sign. This will use more memory than a short integer but around about the same as a long integer.

Date
The date data type is used to store dates, this can contain just a date value, a time value and both of them together for example the date can be read and written in many different formats, when a user enters this information that have to be informed of which format that they have to use. For example this could be just day, month and year (DD/MM/YYYY) or it could also be displayed as:

0:00:00 (midnight) on January 9, 9999.

This would be more informative but would also need more space to be able to store.
Data type
Storage size
Range
Byte
1 byte
0 to 255
Boolean
2 bytes
True or False
Integer
2 bytes
-32,768 to 32,767
Long
(long integer)
4 bytes
-2,147,483,648 to 2,147,483,647
Single
(single-precision floating-point)
4 bytes
-3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values
Double
(double-precision floating-point)
8 bytes
-1.79769313486231E308 to
-4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values
Currency
(scaled integer)
8 bytes
-922,337,203,685,477.5808 to 922,337,203,685,477.5807
Decimal
14 bytes
+/-79,228,162,514,264,337,593,543,950,335 with no decimal point;
+/-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest non-zero number is
+/-0.0000000000000000000000000001
Date
8 bytes
January 1, 100 to December 31, 9999
String
(variable-length)
10 bytes + string length
0 to approximately 2 billion
String
(fixed-length)
Length of string
1 to approximately 65,400

Useful to have different data types
Data types all use different amounts of storage space to store the variable they are to contain, the computer needs to know how much space needs to be reserved and what output to expect from, this helps with the speed of the computer and also ensure that there isn’t too much data for the amount of memory that is available.
In addition to this without knowing the data type the compiler wouldn’t be able to determine what or how to deal with the data as it wouldn’t be in the correct format and wouldn’t be able to process it.
It is also important to have different data types as it demonstrates different information and they can all be manipulated in specific ways for example adding two integers together would output the two numbers being added together, whereas adding two strings together would just add the two sentences one after the other.
A currency data type would have a currency sign whereas a normal float or real wouldn’t be able to contain these types of symbols due it being in the wrong format and the computer wouldn’t be able to process it as it wasn’t expecting it.

Table Used From: https://msdn.microsoft.com/en-gb/library/47zceaw7.aspx


No comments:

Post a Comment