コード例 #1
0
        public static ConversionResult Convert(CoinType from, CoinType to, double amount)
        {
            if (conversionTable == null)
            {
                CreateConversionTable();
            }

            double result    = amount * conversionTable[(int)to, (int)from];
            double remainder = result % 1;

            int[] remainders = new int[currencyCount];

            CoinType current = to;

            while (current != NONE)
            {
                double conversion       = conversionTable[(int)current, (int)to];
                double currentRemainder = Math.Floor(remainder * conversion);
                remainders[(int)current] = (int)currentRemainder;
                remainder = remainder - (currentRemainder / conversion);
                current   = current.GetLowerDenomination();
            }

            return(new ConversionResult((int)result, to, remainders));
        }