/// <summary> /// Formats the specified object as a string. /// </summary> /// <param name="obj">Object with cell data to format.</param> /// <returns>Returns the formatted string.</returns> public string Format(object obj) { string str = string.Empty; try { if (obj is IFormattable) { return(NumberHelper.Format <IFormattable>(obj as IFormattable, this.formatString, (IFormatProvider)this.FormatProvider)); } double?nullable = FormatConverter.TryDouble(obj, true); if (!nullable.HasValue) { if (obj is string) { return((string)(obj as string)); } return(null); } return(((double)nullable.Value).ToString(this.formatString, (IFormatProvider)this.FormatProvider)); } catch { str = FormatConverter.ToString(obj, true); } return(str); }
/// <summary> /// Formats the specified object as a string. /// </summary> /// <param name="obj">Object with cell data to format.</param> /// <returns>Returns the formatted string.</returns> public string Format(object obj) { DateTime time = DateTime.Now; DateTime?nullable = FormatConverter.TryDateTime(obj, true); if (!nullable.HasValue) { return(FormatConverter.ToString(obj, true)); } return(nullable.Value.ToString(this.formatString, (IFormatProvider)this.FormatProvider)); }
/// <summary> /// Formats the specified value. /// </summary> /// <param name="value">The value.</param> /// <returns>Returns the formatted value.</returns> public override string Format(object value) { try { string newValue = FormatConverter.ToString(value, true); string str2 = this.formatString.Replace("\"", ""); if (str2 != null) { newValue = str2.Replace(CommercialAt, newValue); } return(newValue); } catch { } return(string.Empty); }
/// <summary> /// Formats the specified value. /// </summary> /// <param name="obj">The object.</param> /// <returns> /// Returns the string of the formatted value. /// </returns> public override string Format(object obj) { string str = string.Empty; if (FormatConverter.IsNumber(obj)) { bool flag = (base.PartLocaleID == null) || base.PartLocaleID.AllowScience; double?nullable = FormatConverter.TryDouble(obj, true); if (!nullable.HasValue) { return(""); } double num = nullable.Value; if (((Math.Abs(num) <= 99999999999) || !flag) && ((Math.Abs(num) >= 1E-11) || (num == 0.0))) { return(this.DigitalFormat.Format(obj)); } return(this.ExponentialDigitalFormat.Format(obj)); } if (obj is string) { string newValue = FormatConverter.ToString(obj, true); string str3 = DefaultTokens.TrimEscape(this.FormatString.Replace("\"", "")); if (str3 != null) { newValue = str3.Replace("General", newValue); } return(newValue); } if (obj is bool) { bool flag2 = (bool)((bool)obj); str = flag2.ToString().ToUpper(); } return(str); }
/// <summary> /// Formats the specified value. /// </summary> /// <param name="obj">The object.</param> /// <returns>Returns the string of the formatted value.</returns> public override string Format(object obj) { if (obj is bool) { return(FormatConverter.ToString(obj, true)); } double?nullable = FormatConverter.TryDouble(obj, true); if (!nullable.HasValue) { if (obj is string) { return((string)(obj as string)); } return(null); } double num = nullable.Value; string naNSymbol = base.NaNSymbol; if ((this.fractionNumeratorFormat != null) && (this.fractionDenominatorFormat != null)) { double num2; double num3; double num4; double num13; int length = this.fractionDenominatorFormat.Length; if (!GetFraction(num, length, out num2, out num3, out num4)) { return(((double)num).ToString((IFormatProvider)this.NumberFormatInfo)); } double mincCommonMultiple = this.GetMincCommonMultiple(num3, num4); if (mincCommonMultiple > 1.0) { num3 /= mincCommonMultiple; num4 /= mincCommonMultiple; } if (this.fractionIntegerFormat != null) { double num7; double num9; StringBuilder builder = new StringBuilder(); if (num2 != 0.0) { builder.Append(((double)num2).ToString(this.fractionIntegerFormat, (IFormatProvider)this.NumberFormatInfo)); } if (this.constString != null) { builder.Append(this.constString); } if ((num2 == 0.0) && (num < 0.0)) { builder.Append(base.NegativeSign); } if (num == 0.0) { builder.Append("0"); } string fractionDenominatorFormat = this.fractionDenominatorFormat; if (double.TryParse(fractionDenominatorFormat, out num7) && (num7 > 0.0)) { num3 *= num7 / num4; fractionDenominatorFormat = string.Empty; num4 = num7; double num8 = Math.Ceiling(num3) - num3; if ((num8 <= 0.5) && (num8 > 0.0)) { num3 = ((int)num3) + 1; } else { num3 = (int)num3; } } string fractionNumeratorFormat = this.fractionNumeratorFormat; if (double.TryParse(fractionNumeratorFormat, out num9) && (num9 == 0.0)) { int num10 = fractionNumeratorFormat.Length; string str4 = ((double)num3).ToString(); int num11 = str4.Length; if (num10 > num11) { fractionNumeratorFormat = fractionNumeratorFormat.Substring(0, fractionNumeratorFormat.Length - (num10 - num11)); } else if (num10 < num11) { num3 = int.Parse(str4.Substring(0, num10)); } } if (num3 != 0.0) { builder.Append(((double)num3).ToString(fractionNumeratorFormat, (IFormatProvider)this.NumberFormatInfo).TrimStart(new char[] { '0' })); builder.Append(DefaultTokens.SolidusSign); builder.Append(((double)num4).ToString(fractionDenominatorFormat, (IFormatProvider)this.NumberFormatInfo).TrimStart(new char[] { '0' })); } return(builder.ToString()); } StringBuilder builder2 = new StringBuilder(); double a = (num2 * num4) + num3; if (double.TryParse(this.fractionDenominatorFormat, out num13) && (num13 > 0.0)) { a *= num13 / num4; num4 = num13; double num14 = Math.Ceiling(a) - a; if ((num14 <= 0.5) && (num14 > 0.0)) { a = ((int)a) + 1; } else { a = (int)a; } builder2.Append(string.Format("{0}/{1}", (object[])new object[] { ((double)a), ((double)num4) })); } else { builder2.Append(((double)a).ToString(this.fractionNumeratorFormat, (IFormatProvider)this.NumberFormatInfo).TrimStart(new char[] { '0' })); builder2.Append(DefaultTokens.SolidusSign); builder2.Append(((double)num4).ToString(this.fractionDenominatorFormat, (IFormatProvider)this.NumberFormatInfo).TrimStart(new char[] { '0' })); } return(builder2.ToString()); } naNSymbol = ((double)num).ToString(this.EncodeNumberFormat(this.numberFormatString), (IFormatProvider)this.NumberFormatInfo); if (this.NumberStringConverter != null) { naNSymbol = this.NumberStringConverter.ConvertTo(naNSymbol, obj, this.isGeneralNumber, base.PartLocaleID, base.PartDBNumberFormat); } return(naNSymbol); }
/// <summary> /// Formats the specified value. /// </summary> /// <param name="obj">The object.</param> /// <returns>Returns the string of the formatted value.</returns> public override string Format(object obj) { if (obj is bool) { return(FormatConverter.ToString(obj, true)); } string number = string.Empty; DateTime time = DateTime.Now; DateTime?nullable = FormatConverter.TryDateTime(obj, true); if (nullable.HasValue) { time = nullable.Value; if ((((this.validDateTimeFormatString == "H") || (this.validDateTimeFormatString == "h")) || ((this.validDateTimeFormatString == "m") || (this.validDateTimeFormatString == "M"))) || (((this.validDateTimeFormatString == "d") || (this.validDateTimeFormatString == "s")) || (this.validDateTimeFormatString == "y"))) { this.validDateTimeFormatString = "%" + this.validDateTimeFormatString; } number = time.ToString(this.validDateTimeFormatString, (IFormatProvider)this.DateTimeFormatInfo); if (this.hasJD) { string monthName = DefaultTokens.DateTimeFormatInfo.GetMonthName(time.Month); number = number.Replace(PlaceholderMonthJD, monthName.Substring(0, 1)); } if (this.absTimeParts != null) { TimeSpan span = (TimeSpan)(time - this.AbsoluteTime); foreach (ABSTimeFormatPart part in this.absTimeParts) { string newValue = null; switch (part.TimePartType) { case TimePart.Hour: newValue = ((double)Math.Floor(span.TotalHours)).ToString(part.FormatString); break; case TimePart.Minute: newValue = ((double)Math.Floor(span.TotalMinutes)).ToString(part.FormatString); break; case TimePart.Second: newValue = ((double)Math.Floor(span.TotalSeconds)).ToString(part.FormatString); break; } if (newValue != null) { number = number.Replace(DefaultTokens.ReplacePlaceholder + part.Token, newValue); } } } } else { number = FormatConverter.ToString(obj, true); } if (this.NumberStringConverter is DefaultDateTimeNumberStringConverter) { if (this.NumberStringConverter != null) { number = this.NumberStringConverter.ConvertTo(number, obj, false, base.PartLocaleID, base.PartDBNumberFormat); } return(number); } if (this.NumberStringConverter == null) { return(number); } if (this.hasYearDelay) { number = number.Replace(DefaultTokens.ReplacePlaceholder + YearFourDigit, time.ToString(YearFourDigit)).Replace(DefaultTokens.ReplacePlaceholder + YearTwoDigit, time.ToString(YearTwoDigit)); } return(this.NumberStringConverter.ConvertTo(number, obj, true, base.PartLocaleID, base.PartDBNumberFormat)); }