Ejemplo n.º 1
0
 public BigNumber Min(BigNumber right)
 {
     return(BigInteger.Min(this._integer, right._integer));
 }
Ejemplo n.º 2
0
 public BigNumber GreatestCommonDivisor(BigNumber right)
 {
     return(BigInteger.GreatestCommonDivisor(this, right));
 }
Ejemplo n.º 3
0
 public static BigDecimal Cast(decimal value, BigNumber precision)
 {
     return(new BigDecimal(value, precision));
 }
Ejemplo n.º 4
0
 public BigDecimal NewPrecision(BigNumber precision)
 {
     return(new BigDecimal(this.ToString(), precision));
 }
Ejemplo n.º 5
0
        public BigDecimal Fixed(BigNumber precision)
        {
            var left = this;

            var netLeft_Right        = left._integerRight;
            var netLeft_Right_String = netLeft_Right.ToString();

            if (netLeft_Right_String.Length < left.PrecisionLength)
            {
                netLeft_Right_String = "".PadLeft((int)(left.PrecisionLength - netLeft_Right_String.Length), '0') + netLeft_Right_String;
            }

            var intPrecision = (int)precision;

            if (intPrecision >= netLeft_Right_String.Length)
            {
                return(left);
            }

            var plus = false;

            switch (netLeft_Right_String[intPrecision])
            {
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                plus = true;
                break;

            default:
                break;
            }

            var netLeft = (left._integerLeft * left.PrecisionOnlyNormal) + left._integerRight;

            if (plus)
            {
                netLeft += BigNumber.Ten.Pow(left.PrecisionLength - precision);
            }

            if (left._isNeg == true)
            {
                netLeft *= -1;
            }

            var net       = netLeft;
            var net_isNeg = net < 0;

            if (net_isNeg == true)
            {
                net *= -1;
            }

            var net_string = net.ToString();

            if (net_string.Length < left.PrecisionLength + 1)
            {
                net_string = "0" + "".PadLeft((int)(left.PrecisionLength - net_string.Length), '0') + net_string;
            }

            var resultRight = net_string.Substring((int)(net_string.Length - left.PrecisionLength));
            var resultLeft  = net_string.Substring(0, (int)(net_string.Length - resultRight.Length));

            return(new BigDecimal(
                       (net_isNeg ? "-" : "") + resultLeft + "." + resultRight
                       , precision));
        }
Ejemplo n.º 6
0
 public BigDecimal(decimal value, BigNumber precision) : this(value.ToString(ConvertCultureInfo), precision)
 {
 }