public static decimal Format(decimal entryNumber, PriceEndTemplate template) { var strValue = entryNumber.ToString(CultureInfo.InvariantCulture); var fixedDigits = (template.CountFixedDigits == 3) ? 4 : template.CountFixedDigits; var sub = strValue.Substring(0, strValue.Length - fixedDigits); var value = Convert.ToDecimal(sub + template.IntValue); return value / 100; }
public Rule(string priceTemplate, string beginTemplate, string endTemplate) { if (!PriceEndTemplate.Validate(priceTemplate)) throw new ArgumentException(string.Format("wrong format: {0}", priceTemplate), "priceTemplate"); if (!PriceEndTemplate.Validate(beginTemplate)) throw new ArgumentException(string.Format("wrong format: {0}", beginTemplate), "beginTemplate"); if (!PriceEndTemplate.Validate(endTemplate)) throw new ArgumentException(string.Format("wrong format: {0}", endTemplate), "endTemplate"); PriceTemplate = new PriceEndTemplate(priceTemplate); BeginTemplate = new PriceEndTemplate(beginTemplate); EndTemplate = new PriceEndTemplate(endTemplate); if (PriceTemplate.CountFixedDigits != BeginTemplate.CountFixedDigits || BeginTemplate.CountFixedDigits != EndTemplate.CountFixedDigits) throw new ArgumentException("All templates must have the same quantity of fixed digits."); }