The Decimal Type  
Author Message
Karim Hemani





PostPosted: Visual C# Language, The Decimal Type Top

I was reading the MSDN description of the decimal type and it gives the range for this type as follows:

±1.0 × 10 28 to ±7.9 × 1028

I am not sure how to interpret this. Usually, the range is stated as <smallest number, largest number>, but here we have +/- in front of each number. Is it correct to interpret the above range as follows:

+1.0 × 10 28 to +7.9 × 1028

and

-1.0 × 10 28 to -7.9 × 1028

including, as well,

0.

Please advise if I am getting it right.

Karim



Visual C#7  
 
 
MarcD





PostPosted: Visual C# Language, The Decimal Type Top

I'm not sure where you pulled that information from and sinec you did not provide you a link I went ahead and hit F1 for you. Below is what the msdn ACTUALLY says about the Decimal type. I have highlighted key terms
 

The Decimal value type represents decimal numbers ranging from positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335. The Decimal value type is appropriate for financial calculations requiring large numbers of significant integral and fractional digits and no round-off errors.

A decimal number is a floating-point value that consists of a sign, a numeric value where each digit in the value ranges from 0 to 9, and a scaling factor that indicates the position of a floating decimal point that separates the integral and fractional parts of the numeric value.

The binary representation of a Decimal value consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the 96-bit integer and specify what portion of it is a decimal fraction. The scaling factor is implicitly the number 10, raised to an exponent ranging from 0 to 28. Therefore, the binary representation of a Decimal value is of the form, ((-296 to 296) / 10(0 to 28)), where -296-1 is equal to MinValue, and 296-1 is equal to MaxValue.


 
 
Karim Hemani





PostPosted: Visual C# Language, The Decimal Type Top

The link to the article in MSDN about which I had the confusion is as follows:

http://msdn.microsoft.com/library/default.asp url=/library/en-us/csref/html/vcrefthedecimaltype.asp

Karim


 
 
MarcD





PostPosted: Visual C# Language, The Decimal Type Top

Type Approximate Range Precision .NET type
decimal ±1.0 × 10 28 to ±7.9 × 1028 28-29 significant digits .Decimal
see above.