От: | nikov | http://www.linkedin.com/in/nikov | |
Дата: | 29.03.07 07:05 | ||
Оценка: | 18 (2) | ||
#Имя: | FAQ.dotnet.decimal |
Decimal Structure
.....
The scaling factor also preserves any trailing zeroes in a Decimal number. Trailing zeroes do not affect the value of a Decimal number in arithmetic or comparison operations. However, trailing zeroes can be revealed by the ToString method if an appropriate format string is applied.
using System;
using System.Globalization;
class Program
{
static void Main()
{
decimal x = decimal.Parse("0.10", CultureInfo.InvariantCulture);
decimal y = decimal.Parse("0.100", CultureInfo.InvariantCulture);
Console.WriteLine(x == y);
Console.WriteLine(x.Equals(y));
Console.WriteLine(BitConverter.ToString(ToByteArray(decimal.GetBits(x))));
Console.WriteLine(BitConverter.ToString(ToByteArray(decimal.GetBits(y))));
Console.WriteLine(x.ToString(CultureInfo.InvariantCulture));
Console.WriteLine(y.ToString(CultureInfo.InvariantCulture));
}
static byte[] ToByteArray(int[] source)
{
if (source == null) throw new ArgumentNullException("source");
int len = source.Length * sizeof (int);
byte[] dest = new byte[len];
Buffer.BlockCopy(source, 0, dest, 0, len);
return dest;
}
}
True
True
0A-00-00-00-00-00-00-00-00-00-00-00-00-00-02-00
64-00-00-00-00-00-00-00-00-00-00-00-00-00-03-00
0.10
0.100