当前位置: 首页>>代码示例>>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;未经允许,请勿转载。