view previous lesson4
Integral Types
In C#, an integral is a category of types. For anyone confused because the word Integral sounds like a mathematical term, from the perspective of C# programming, these are actually defined as Integral types in the C# programming language specification. They are whole numbers, either signed or unsigned, and the char type. The char type is a Unicode character, as defined by the Unicode Standard. For more information, visit The Unicode Home Page. table 2-1 shows the integral types, their size, and range.
Table 2-1. The Size and Range of C# Integral Types
Type | Size (in bits) | Range |
---|---|---|
sbyte | 8 | -128 to 127 |
byte | 8 | 0 to 255 |
short | 16 | -32768 to 32767 |
ushort | 16 | 0 to 65535 |
int | 32 | -2147483648 to 2147483647 |
uint | 32 | 0 to 4294967295 |
long | 64 | -9223372036854775808 to 9223372036854775807 |
ulong | 64 | 0 to 18446744073709551615 |
char | 16 | 0 to 65535 |
Integral types are well suited for those operations involving whole number calculations. The char type is the exception, representing a single Unicode character. As you can see from the table above, you have a wide range of options to choose from, depending on your requirements.
Floating Point and Decimal Types
A C# floating point type is either a float or double. They are used any time you need to represent a real number, as defined by IEEE 754. For more information on IEEE 754, visit the IEEE Web Site. Decimal types should be used when representing financial or money values. table 2-2 shows the floating point and decimal types, their size, precision, and range.
Table 2-2. The Floating Point and Decimal Types with Size, precision, and Range
Type | Size (in bits) | precision | Range |
---|---|---|---|
float | 32 | 7 digits | 1.5 x 10-45 to 3.4 x 1038 |
double | 64 | 15-16 digits | 5.0 x 10-324 to 1.7 x 10308 |
decimal | 128 | 28-29 decimal places | 1.0 x 10-28 to 7.9 x 1028 |
Floating point types are used when you need to perform operations requiring fractional representations. However, for financial calculations, the decimal type is the best choice because you can avoid rounding errors.
This is a really informative knowledge, Thanks for posting this informative Information. Covid-19 Cleaning Services Ridley Park
ReplyDelete