예제 #1
0
        public static PrefixSuffixEntry CalculatePrice(decimal price)
        {
            var    entry     = new PrefixSuffixEntry();
            String strPrice  = String.Format(CultureInfo.InvariantCulture, "{0:0.000000}", price);
            String strSuffix = "";

            while (strPrice.EndsWith("0"))
            {
                strPrice   = strPrice.Remove(strPrice.Length - 1);
                strSuffix += "0";
            }
            entry.Suffix = strSuffix;
            entry.Prefix = strPrice;
            return(entry);
        }
예제 #2
0
        public static PrefixSuffixEntry CalculateAmount(decimal amount)
        {
            var     entry    = new PrefixSuffixEntry();
            decimal fraction = amount - Math.Floor(amount);

            entry.Prefix = String.Format(CultureInfo.InvariantCulture, "{0:F0}", amount);
            int fractions = 5 - entry.Prefix.Length;

            if (fractions > 0)
            {
                fraction = Math.Round(fraction, fractions);
                var format = String.Format(CultureInfo.InvariantCulture, "{{0:F{0}}}", fractions);
                var result = String.Format(CultureInfo.InvariantCulture, format, fraction);
                entry.Suffix = result.Remove(0, 1);
            }
            return(entry);
        }