Visual C++ .NET/Data Type/Decimal
Содержание
Break decimal up into 4 parts
#include "stdafx.h"
using namespace System;
void main()
{
Decimal a = (Decimal)123456789012345000000.00000000;
Console::WriteLine( a );
array<int>^ d = Decimal::GetBits(a);
Console::WriteLine( d[0] );
Console::WriteLine( d[1] );
Console::WriteLine( d[2] );
Console::WriteLine( d[3].ToString("X") );
}
Cast to decimal
#include "stdafx.h"
using namespace System;
void main()
{
Decimal x = (Decimal)0.1234567890123456789012345678; // will get truncated
Decimal y = (Decimal)0.0000000000000000789012345678; // works fine
Console::WriteLine( x );
Console::WriteLine( y );
}
Decimal calculation
#include "stdafx.h"
using namespace System;
void main()
{
Decimal a = (Decimal)123456789012345000000.00000000;
Decimal b = (Decimal)678901.23456780;
Decimal c = -(a + b);
Console::WriteLine( c );
}
Decimal constructor
#include "stdafx.h"
using namespace System;
void main()
{
Decimal z(0xeb1f0ad2, 0xab54a98c, 0, false, 0); // = 12345678901234567890
Console::WriteLine( z );
}
Decimal literal assigned
#include "stdafx.h"
using namespace System;
void main()
{
int x = 456789; //
Console::WriteLine( x );
}
Using Decimal constructor
#include "stdafx.h"
using namespace System;
void main()
{
Decimal e(0, 1, 2, // digits
((3 & 0x80000000) == 0x80000000), // sign
((3 >> 16) & 0xff) ); // decimal location
Console::WriteLine( e );
}