Fan.Sys.FanNum.toLocale C# (CSharp) Méthode

toLocale() static private méthode

static private toLocale ( NumPattern p, NumDigits d, NumberFormatInfo df ) : string
p NumPattern
d NumDigits
df System.Globalization.NumberFormatInfo
Résultat string
        internal static string toLocale(NumPattern p, NumDigits d, NumberFormatInfo df)
        {
            // string buffer
              StringBuilder s = new StringBuilder();
              if (d.negative) s.Append(df.NegativeSign);

              // if we have more frac digits then maxFrac, then round off
              d.round(p.maxFrac);

              // if we have an optional integer part, and only
              // fractional digits, then don't include leading zero
              int start = 0;
              if (p.optInt && d.zeroInt()) start = d.dec;

              // if min required fraction digits are zero and we
              // have nothing but zeros, then truncate to a whole number
              if (p.minFrac == 0 && d.zeroFrac(p.maxFrac)) d.size = d.dec;

              // leading zeros
              for (int i=0; i<p.minInt-d.dec; ++i) s.Append('0');

              // walk thru the digits and apply locale symbols
              bool dec = false;
              for (int i=start; i<d.size; ++i)
              {
            if (i < d.dec)
            {
              if ((d.dec - i) % p.group == 0 && i > 0)
            s.Append(df.NumberGroupSeparator);
            }
            else
            {
              if (i == d.dec && p.maxFrac > 0)
              {
            s.Append(df.NumberDecimalSeparator);
            dec = true;
              }
              if (i-d.dec >= p.maxFrac) break;
            }
            s.Append(d.digits[i]);
              }

              // trailing zeros
              for (int i=0; i<p.minFrac-d.fracSize(); ++i)
              {
            if (!dec) { s.Append(df.NumberDecimalSeparator); dec = true; }
            s.Append('0');
              }

              // handle #.# case
              if (s.Length == 0) return "0";

              return s.ToString();
        }

Usage Example

Exemple #1
0
        public static String toLocale(long self, string pattern)
        {
            // if pattern is "B" format as bytes
            if (pattern != null && pattern.Length == 1 && pattern[0] == 'B')
            {
                return(toLocaleBytes(self));
            }

            // get current locale
            Locale           locale = Locale.cur();
            NumberFormatInfo df     = locale.dec();

            // get default pattern if necessary
            if (pattern == null)
            {
                pattern = Env.cur().locale(Sys.m_sysPod, "int", "#,###");
            }

            // parse pattern and get digits
            NumPattern p = NumPattern.parse(pattern);
            NumDigits  d = new NumDigits(self);

            // route to common FanNum method
            return(FanNum.toLocale(p, d, df));
        }
All Usage Examples Of Fan.Sys.FanNum::toLocale