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)); }
public static string toLocale(double self, string pattern) { try { // get current locale Locale locale = Locale.cur(); NumberFormatInfo df = locale.dec(); // handle special values if (System.Double.IsNaN(self)) { return(df.NaNSymbol); } if (self == System.Double.PositiveInfinity) { return(df.PositiveInfinitySymbol); } if (self == System.Double.NegativeInfinity) { return(df.NegativeInfinitySymbol); } // get default pattern if necessary if (pattern == null) { pattern = Env.cur().locale(Sys.m_sysPod, "float", "#,###.0##"); } // TODO: if value is < 10^-3 or > 10^7 it will be // converted to exponent string, so just bail on that string str = Double.toString(self); if (str.IndexOf('E') > 0) { str = self.ToString("0.#########"); } // parse pattern and get digits NumPattern p = NumPattern.parse(pattern); NumDigits d = new NumDigits(str); // route to common FanNum method return(FanNum.toLocale(p, d, df)); } catch (Exception e) { Err.dumpStack(e); return(self.ToString()); } }
public static string toLocale(BigDecimal self, string pattern) { // 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, "decimal", "#,###.0##"); } // 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)); }