當前位置: 首頁>>代碼示例>>C#>>正文


C# System.Currency類代碼示例

本文整理匯總了C#中System.Currency的典型用法代碼示例。如果您正苦於以下問題:C# Currency類的具體用法?C# Currency怎麽用?C# Currency使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Currency類屬於System命名空間,在下文中一共展示了Currency類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetDiscountPrices

        private IList<IPriceValue> GetDiscountPrices(IList<IPriceValue> prices, MarketId marketId, Currency currency)
        {
            currency = GetCurrency(currency, marketId);

            var priceValues = new List<IPriceValue>();
            
            _promotionHelper.Reset();
            
            foreach (var entry in GetEntries(prices))
            {
                var price = prices
                    .OrderBy(x => x.UnitPrice.Amount)
                    .FirstOrDefault(x => x.CatalogKey.CatalogEntryCode.Equals(entry.Code) &&
                        x.UnitPrice.Currency.Equals(currency));
                if (price == null)
                {
                    continue;
                }

                priceValues.Add(_promotionEntryService.GetDiscountPrice(
                    price, entry, currency, _promotionHelper));
                
            }
            return priceValues;
        }
開發者ID:ocrenaka,項目名稱:Quicksilver,代碼行數:25,代碼來源:PromotionService.cs

示例2: CompareToTest

        public void CompareToTest()
        {
            Currency currency = new Currency("USD", "USD");
            Money target = new Money(100, currency);
            Money other = null;
            int actual;

            try
            {
                actual = target.CompareTo(other);
                Assert.Fail("Expected ArgumentNullException");
            }
            catch (ArgumentNullException) { }

            target = new Money(100, currency);
            other = new Money(100, currency);
            actual = target.CompareTo(other);
            Assert.AreEqual<int>(0, actual);

            target = new Money(50, currency);
            other = new Money(100, currency);
            actual = target.CompareTo(other);
            Assert.AreEqual<int>(-1, actual);

            target = new Money(50, currency);
            other = new Money(20, currency);
            actual = target.CompareTo(other);
            Assert.AreEqual<int>(1, actual);
        }
開發者ID:robukoo,項目名稱:SimpleBankingSystem,代碼行數:29,代碼來源:MoneyTest.cs

示例3: GetDepth

 public Depth GetDepth(Currency currency)
 {
     DepthResponse depthResponse = restClient.GetResponse<DepthResponse>(String.Format("BTC{0}/money/depth/fetch", currency.ToString()), Method.GET, null, AccessType.Public);
     if (depthResponse.Depth == null)
         throw new Exception("Failed to deserialize JSON object of type " + typeof(Depth) + ". " + MtGoxRestClient.lastResponse);
     return depthResponse.Depth;
 }
開發者ID:jamez1,項目名稱:botcoin,代碼行數:7,代碼來源:MtGoxTradeCommands.cs

示例4: GetBestDeal

 public async Task<ActionResult> GetBestDeal(DateTime startDate, DateTime endDate, Currency baseCurrency, decimal amount)
 {
     try
     {
         var allCurrencies = CommonUtils.EnumUtil.GetValues<Currency>();
         var calcullatorCurrencies = allCurrencies.Where(c => c != baseCurrency).ToArray();
         var calculatorResult = await _ratesCalculator.CalculateBestDealAsync(startDate, endDate, baseCurrency, calcullatorCurrencies, amount);
         var result = new
         {
             CalculationParameters = new
             {
                 StartDate = startDate,
                 EndDate = endDate,
                 BaseCurrency = baseCurrency,
                 Amount = amount
             },
             CalculationResult = calculatorResult.Item1,
             // need to convert rates dictionary, because standard MVC json serializer can't seriale dictionary where key is enum
             // http://stackoverflow.com/questions/2892910/problems-with-json-serialize-dictionaryenum-int32 
             Rates = calculatorResult.Item2.Select(x => new { x.Date, x.Holiday, Rates = x.Rates.ToJsonDictionary() }) 
         };
         return Json(result, JsonRequestBehavior.AllowGet);
     }
     catch (Exception ex)
     {
         _logger.Error(ex, "Error: failed to CalculateBestDeal.");
         throw;
     }
 }
開發者ID:andrewtsw,項目名稱:Interesnee.BadBroker,代碼行數:29,代碼來源:RateController.cs

示例5: Trasaction

 public Trasaction(decimal balance, decimal ammount, TransactionType transactionType, Currency currency)
 {
     this.balance = balance;
     this.ammount = ammount;
     this.transactionType = transactionType;
     this.currency = currency;
 }
開發者ID:alexcompton,項目名稱:BankConsole,代碼行數:7,代碼來源:Transaction.cs

示例6: Get

        /// <summary>
        /// Gets exchange rate 'from' currency 'to' another currency.
        /// </summary>
        public static decimal Get(Currency from, Currency to)
        {
            // exchange rate is 1:1 for same currency
            if (from == to) return 1;

            // use web service to query current exchange rate
            // request : http://download.finance.yahoo.com/d/quotes.csv?s=EURUSD=X&f=sl1d1t1c1ohgv&e=.csv
            // response: "EURUSD=X",1.0930,"12/29/2015","6:06pm",-0.0043,1.0971,1.0995,1.0899,0
            var key = string.Format("{0}{1}", from, to); // e.g. EURUSD means "How much is 1 EUR in USD?".
            // if we've already downloaded this exchange rate, use the cached value
            if (s_rates.ContainsKey(key)) return s_rates[key];

            // otherwise create the request URL, ...
            var url = string.Format(@"http://download.finance.yahoo.com/d/quotes.csv?s={0}=X&f=sl1d1t1c1ohgv&e=.csv", key);
            // download the response as string
            var data = new WebClient().DownloadString(url);
            // split the string at ','
            var parts = data.Split(',');
            // convert the exchange rate part to a decimal
            var rate = decimal.Parse(parts[1], CultureInfo.InvariantCulture);
            // cache the exchange rate
            s_rates[key] = rate;

            // and finally perform the currency conversion
            return rate;
        }
開發者ID:rkerschbaumer,項目名稱:oom,代碼行數:29,代碼來源:ExchangeRates.cs

示例7: Main

        static void Main(string[] args)
        {
            try
            {
                   Currency balance = new Currency(50,35);

                   Console.WriteLine(balance);
                   Console.WriteLine("balance is " + balance);
                   Console.WriteLine("balance is (using ToString()) " + balance.ToString());

                   float balance2 = balance;

                   Console.WriteLine("After converting to float, = " + balance2);

                   balance = (Currency)balance2;

                   Console.WriteLine("After converting back to Currency, = " + balance);
                   Console.WriteLine("Now attempt to convert out of range value of " +
                                     "-$50.50 to a Currency:");

                checked
                {
                    balance = (Currency)(-50.50);
                    Console.WriteLine("Result is " + balance.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception occurred: " + e.Message);
            }

            Console.ReadLine();
        }
開發者ID:Ricky-Hao,項目名稱:ProCSharp,代碼行數:33,代碼來源:Program.cs

示例8: ForexRate

 public ForexRate(Currency currency, double rate, int day)
     : this()
 {
     Currency = currency;
     Rate = rate;
     Day = day;
 }
開發者ID:stasetzzz,項目名稱:ProgTech,代碼行數:7,代碼來源:ForexRate.cs

示例9: MoneyForExercise2

 /// <summary>
 /// Represents a money.
 /// </summary>
 /// <param name="value">Value for the money.</param>
 public MoneyForExercise2(decimal value, Currency currency)
 {
     this.value = value;
     this.MinValue = 6;
     //
     this.currency = currency;
 }
開發者ID:bernardobrezende,項目名稱:IntroDotNetCSharp,代碼行數:11,代碼來源:MoneyForExercise2.cs

示例10: update

        public HttpResponseMessage update(Currency post)
        {
            // Check for errors
            if (post == null)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The post is null");
            }

            // Make sure that the data is valid
            post.currency_code = AnnytabDataValidation.TruncateString(post.currency_code, 3);
            post.conversion_rate = AnnytabDataValidation.TruncateDecimal(post.conversion_rate, 0, 9999.999999M);

            // Get the saved post
            Currency savedPost = Currency.GetOneById(post.currency_code);

            // Check if the post exists
            if (savedPost == null)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The record does not exist");
            }

            // Update the post
            Currency.Update(post);

            // Return the success response
            return Request.CreateResponse<string>(HttpStatusCode.OK, "The update was successful");

        } // End of the update method
開發者ID:raphaelivo,項目名稱:a-webshop,代碼行數:28,代碼來源:currenciesController.cs

示例11: add

        public HttpResponseMessage add(Currency post)
        {
            // Check for errors
            if (post == null)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The post is null");
            }

            // Make sure that the data is valid
            post.currency_code = AnnytabDataValidation.TruncateString(post.currency_code, 3);
            post.conversion_rate = AnnytabDataValidation.TruncateDecimal(post.conversion_rate, 0, 9999.999999M);

            // Check if the currency exists
            if(Currency.MasterPostExists(post.currency_code) == true)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The currency already exists");
            }

            // Add the post
            Currency.Add(post);

            // Return the success response
            return Request.CreateResponse<string>(HttpStatusCode.OK, "The post has been added");

        } // End of the add method
開發者ID:raphaelivo,項目名稱:a-webshop,代碼行數:25,代碼來源:currenciesController.cs

示例12: FormatCurrency

        public string FormatCurrency(decimal amount, Currency targetCurrency, bool includeSymbol = true)
        {
            //find out the culture for the target currency
            var culture = CultureInfo.GetCultures(CultureTypes.SpecificCultures).FirstOrDefault(c =>
            {
                var r = new RegionInfo(c.LCID);
                return string.Equals(r.ISOCurrencySymbol, targetCurrency.CurrencyCode, StringComparison.CurrentCultureIgnoreCase);
            });

            //the format of display
            var format = targetCurrency.DisplayFormat;
            var locale = targetCurrency.DisplayLocale;

            if (culture == null)
            {
                if (!string.IsNullOrEmpty(locale))
                {
                    culture = new CultureInfo(locale);
                }
            }

            if (string.IsNullOrEmpty(format))
            {
                format = culture == null || !includeSymbol ? "{0:N}" : "{0:C}";
            }

            return culture == null ? string.Format(format, amount): string.Format(culture, format, amount);
        }
開發者ID:Console-Byte,項目名稱:mobsocial,代碼行數:28,代碼來源:FormatterService.cs

示例13: Parse

        /// <summary>Converts the string representation of a money value to its <see cref="Money"/> equivalent.</summary>
        /// <param name="value">The string representation of the number to convert.</param>
        /// <param name="currency">The currency to use for parsing the string representation.</param>
        /// <returns>The equivalent to the money amount contained in <i>value</i>.</returns>
        /// <exception cref="System.ArgumentNullException"><i>value</i> is <b>null</b> or empty.</exception> 
        /// <exception cref="System.FormatException"><i>value</i> is not in the correct format or the currency sign matches with multiple known currencies!</exception>
        /// <exception cref="System.OverflowException"><i>value</i> represents a number less than <see cref="Decimal.MinValue"/> or greater than <see cref="Decimal.MaxValue"/>.</exception>
        public static Money Parse(string value, Currency currency)
        {
            if (string.IsNullOrWhiteSpace(value))
                throw new ArgumentNullException(nameof(value));

            return Parse(value, NumberStyles.Currency, GetNumberFormatInfo(currency, null), currency);
        }
開發者ID:JayT82,項目名稱:NodaMoney-1,代碼行數:14,代碼來源:Money.Parsable.cs

示例14: OnLoadFromConfig

        protected override void OnLoadFromConfig(ConfigNode node)
        {
            base.OnLoadFromConfig(node);

            currency = ConfigNodeUtil.ParseValue<Currency>(node, "currency");
            advance = ConfigNodeUtil.ParseValue<double>(node, "advance");
        }
開發者ID:jrossignol,項目名稱:Strategia,代碼行數:7,代碼來源:AdvanceEffect.cs

示例15: DomainCreditPaymentPlanItem

 public DomainCreditPaymentPlanItem(double mainSum, double percentSum, Currency currency, DateTime startDate)
 {
     MainSum = mainSum;
     PercentSum = percentSum;
     Currency = currency;
     StartDate = startDate;
 }
開發者ID:kateEvstratenko,項目名稱:Bank,代碼行數:7,代碼來源:DomainCreditPaymentPlanItem.cs


注:本文中的System.Currency類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。