Ejemplo n.º 1
0
 // Converts a Decimal to a long. The Decimal value is rounded towards zero
 // to the nearest integer value, and the result of this operation is
 // returned as a long.
 //
 public static long ToInt64(Decimal d)
 {
     if (d.Scale != 0)
     {
         DecCalc.VarDecFix(ref d);
     }
     if (d.uhi == 0)
     {
         long l = d.ulo | (long)(int)d.umid << 32;
         if (!d.Sign)
         {
             if (l >= 0)
             {
                 return(l);
             }
         }
         else
         {
             l = -l;
             if (l <= 0)
             {
                 return(l);
             }
         }
     }
     throw new OverflowException(SR.Overflow_Int64);
 }
Ejemplo n.º 2
0
 // Converts a Decimal to an integer. The Decimal value is rounded towards
 // zero to the nearest integer value, and the result of this operation is
 // returned as an integer.
 //
 public static int ToInt32(Decimal d)
 {
     if (d.Scale != 0)
     {
         DecCalc.VarDecFix(ref d);
     }
     if (d.hi == 0 && d.mid == 0)
     {
         int i = d.lo;
         if (!d.Sign)
         {
             if (i >= 0)
             {
                 return(i);
             }
         }
         else
         {
             i = -i;
             if (i <= 0)
             {
                 return(i);
             }
         }
     }
     throw new OverflowException(SR.Overflow_Int32);
 }
Ejemplo n.º 3
0
 public static uint ToUInt32(Decimal d)
 {
     if (d.Scale != 0)
     {
         DecCalc.VarDecFix(ref d);
     }
     if (d.uhi == 0 && d.umid == 0)
     {
         if (!d.Sign || d.ulo == 0)
         {
             return(d.ulo);
         }
     }
     throw new OverflowException(SR.Overflow_UInt32);
 }
Ejemplo n.º 4
0
 public static ulong ToUInt64(Decimal d)
 {
     if (d.Scale != 0)
     {
         DecCalc.VarDecFix(ref d);
     }
     if (d.uhi == 0)
     {
         ulong l = (ulong)d.ulo | ((ulong)d.umid << 32);
         if (!d.Sign || l == 0)
         {
             return(l);
         }
     }
     throw new OverflowException(SR.Overflow_UInt64);
 }
Ejemplo n.º 5
0
 // Truncates a Decimal to an integer value. The Decimal argument is rounded
 // towards zero to the nearest integer value, corresponding to removing all
 // digits after the decimal point.
 //
 public static Decimal Truncate(Decimal d)
 {
     DecCalc.VarDecFix(ref d);
     return(d);
 }