/// <summary> /// GetCurrencyFraction gets a CurrencyFraction for a given currency Id /// </summary> /// <param name="currencyId">The currency Id to get the CurrencyFraction for</param> /// <returns>A CurrencyFraction for a given currency Id</returns> public static CurrencyFraction GetCurrencyFraction(string currencyId) { if (NCldr.CurrencyFractions == null) { return(null); } CurrencyFraction currencyFraction = (from cf in NCldr.CurrencyFractions where string.Compare(cf.Id, currencyId, StringComparison.InvariantCulture) == 0 select cf).FirstOrDefault(); if (currencyFraction != null) { return(currencyFraction); } // return the default return((from cf in NCldr.CurrencyFractions where string.Compare(cf.Id, "DEFAULT", StringComparison.InvariantCulture) == 0 select cf).FirstOrDefault()); }
private static CurrencyFraction[] GetCurrencyFractions() { if (options != null && !options.IncludeCurrencyFractions) { return(null); } List <XElement> infoElements = (from i in supplementalDataDocument.Elements("supplementalData") .Elements("currencyData").Elements("fractions").Elements("info") select i).ToList(); if (infoElements.Count == 0) { return(null); } List <CurrencyFraction> currencyFractions = new List <CurrencyFraction>(); foreach (XElement infoElement in infoElements) { string currencyId = infoElement.Attribute("iso4217").Value.ToString(); Progress("Adding currency fraction", currencyId); CurrencyFraction currencyFraction = new CurrencyFraction(); currencyFraction.Id = currencyId; currencyFraction.Digits = int.Parse(infoElement.Attribute("digits").Value.ToString()); currencyFraction.Rounding = int.Parse(infoElement.Attribute("rounding").Value.ToString()); XAttribute cashRoundingAttribute = infoElement.Attribute("cashRounding"); if (cashRoundingAttribute != null) { currencyFraction.CashRounding = int.Parse(cashRoundingAttribute.Value.ToString()); } currencyFractions.Add(currencyFraction); Progress("Added currency fraction", currencyId, ProgressEventType.Added, currencyFraction); } return(currencyFractions.ToArray()); }
/// <summary> /// CreateNumberFormatInfo creates a .NET NumberFormatInfo for the CLDR Culture /// </summary> /// <param name="culture">The Culture to get the NumberFormatInfo for</param> /// <returns>A .NET NumberFormatInfo for the CLDR Culture</returns> private static NumberFormatInfo CreateNumberFormatInfo(Culture culture) { if (culture.Numbers == null) { return(null); } NumberFormatInfo numberFormatInfo = new NumberFormatInfo(); if (culture.Numbers.CurrentCurrencyPeriod != null) { string currencyId = culture.Numbers.CurrentCurrencyPeriod.Id; CurrencyFraction currencyFraction = NCldr.GetCurrencyFraction(currencyId); if (currencyFraction != null) { numberFormatInfo.CurrencyDecimalDigits = currencyFraction.Digits; } } if (culture.Numbers.DefaultNumberingSystem != null && culture.Numbers.DefaultNumberingSystem.Symbols != null) { NumberingSystem numberingSystem = culture.Numbers.DefaultNumberingSystem; NumberingSystemSymbols symbols = numberingSystem.Symbols; NumberingSystemType numberingSystemType = numberingSystem.NumberingSystemType; CurrencyPeriod currentCurrencyPeriod = culture.Numbers.CurrentCurrencyPeriod; if (!string.IsNullOrEmpty(symbols.Nan)) { numberFormatInfo.NaNSymbol = symbols.Nan; } if (!string.IsNullOrEmpty(symbols.Infinity)) { string minusSign = "-"; if (!string.IsNullOrEmpty(symbols.MinusSign)) { minusSign = symbols.MinusSign; } numberFormatInfo.NegativeInfinitySymbol = minusSign + symbols.Infinity; } if (!string.IsNullOrEmpty(symbols.MinusSign)) { numberFormatInfo.NegativeSign = symbols.MinusSign; } if (!string.IsNullOrEmpty(symbols.Infinity)) { numberFormatInfo.PositiveInfinitySymbol = symbols.Infinity; } if (!string.IsNullOrEmpty(symbols.PercentSign)) { numberFormatInfo.PercentSymbol = symbols.PercentSign; } if (!string.IsNullOrEmpty(symbols.PerMille)) { numberFormatInfo.PerMilleSymbol = symbols.PerMille; } if (!string.IsNullOrEmpty(symbols.PlusSign)) { numberFormatInfo.PositiveSign = symbols.PlusSign; } if (!string.IsNullOrEmpty(symbols.Decimal)) { numberFormatInfo.CurrencyDecimalSeparator = symbols.Decimal; numberFormatInfo.NumberDecimalSeparator = symbols.Decimal; numberFormatInfo.PercentDecimalSeparator = symbols.Decimal; } if (!string.IsNullOrEmpty(symbols.Group)) { numberFormatInfo.CurrencyGroupSeparator = symbols.Group; numberFormatInfo.NumberGroupSeparator = symbols.Group; numberFormatInfo.PercentGroupSeparator = symbols.Group; } if (numberingSystemType != null && numberingSystemType.DigitsOrRules == NumberingSystemDigitsOrRules.Numeric) { numberFormatInfo.NativeDigits = numberingSystemType.DigitsArray; } if (currentCurrencyPeriod != null) { CurrencyDisplayNameSet currencyDisplayNameSet = (from cdns in culture.Numbers.CurrencyDisplayNameSets where string.Compare(cdns.Id, currentCurrencyPeriod.Id, StringComparison.InvariantCulture) == 0 select cdns).FirstOrDefault(); if (currencyDisplayNameSet != null && !string.IsNullOrEmpty(currencyDisplayNameSet.Symbol)) { numberFormatInfo.CurrencySymbol = currencyDisplayNameSet.Symbol; } } if (numberingSystemType == null) { numberFormatInfo.DigitSubstitution = DigitShapes.None; } else { numberFormatInfo.DigitSubstitution = numberingSystemType.DigitShapes; } if (!string.IsNullOrEmpty(numberingSystem.CurrencyFormatPattern)) { numberFormatInfo.CurrencyPositivePattern = numberingSystem.CurrencyPositivePattern; numberFormatInfo.CurrencyNegativePattern = numberingSystem.CurrencyNegativePattern; numberFormatInfo.CurrencyGroupSizes = numberingSystem.CurrencyGroupSizes; } if (!string.IsNullOrEmpty(numberingSystem.PercentFormatPattern)) { numberFormatInfo.PercentDecimalDigits = numberingSystem.PercentDecimalDigits; numberFormatInfo.PercentGroupSizes = numberingSystem.PercentGroupSizes; numberFormatInfo.PercentNegativePattern = numberingSystem.PercentNegativePattern; numberFormatInfo.PercentPositivePattern = numberingSystem.PercentPositivePattern; } if (!string.IsNullOrEmpty(numberingSystem.DecimalFormatPattern)) { numberFormatInfo.NumberDecimalDigits = numberingSystem.NumberDecimalDigits; numberFormatInfo.NumberGroupSizes = numberingSystem.NumberGroupSizes; numberFormatInfo.NumberNegativePattern = numberingSystem.NumberNegativePattern; } } return(numberFormatInfo); }