本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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;
}
}
示例5: Trasaction
public Trasaction(decimal balance, decimal ammount, TransactionType transactionType, Currency currency)
{
this.balance = balance;
this.ammount = ammount;
this.transactionType = transactionType;
this.currency = currency;
}
示例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;
}
示例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();
}
示例8: ForexRate
public ForexRate(Currency currency, double rate, int day)
: this()
{
Currency = currency;
Rate = rate;
Day = day;
}
示例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;
}
示例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
示例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
示例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);
}
示例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);
}
示例14: OnLoadFromConfig
protected override void OnLoadFromConfig(ConfigNode node)
{
base.OnLoadFromConfig(node);
currency = ConfigNodeUtil.ParseValue<Currency>(node, "currency");
advance = ConfigNodeUtil.ParseValue<double>(node, "advance");
}
示例15: DomainCreditPaymentPlanItem
public DomainCreditPaymentPlanItem(double mainSum, double percentSum, Currency currency, DateTime startDate)
{
MainSum = mainSum;
PercentSum = percentSum;
Currency = currency;
StartDate = startDate;
}