Click to See Complete Forum and Search --> : Decimal to UInt32
Bandit
May 2nd, 2007, 02:37 AM
hi. guys i want to convert a decimal value to uint32 value. how can i convert it without removing the decimal places and convert the converted uint32 value to decimal value.
example :
decimal x = 10.120;
uint32 b;
decimal c;
b = x;
c = b; (the c value should be 10.120 )
any one know how to do this?
thanks...
Homogenn
May 2nd, 2007, 03:34 AM
You can't. You have to keep the original Decimal to do that. If you want, you can always make a property to extract it as an unsigned integer
public UInt32 AsUInt
{
get{return (UInt32)x;}
}
dcell59
May 2nd, 2007, 01:08 PM
Right, you can't do it the way you wrote the code. However, if there is some special reason you need to use ints, you can multiply and divide (as long as you don't have to worry about overflow). I wouldn't think you'd need to do this in C#. Back in the Windows 3.1 days, when you couldn't be sure you had floating point hardware or a version of sprintf that handled floats, it was common to store small-ish decimal numbers in longs by multiplying by 100 and then using mod and divide when it was time to format them.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.