using Microsoft.VisualBasic; using Microsoft.VisualBasic.CompilerServices; using System; namespace MuchInfo.Chart.WPF.Helpers { public class TextFormatting { /// /// Formats the number. /// /// A value. /// The significant digits. /// if set to true [allow abbreviate]. /// System.Object. public static string FormatNumber(float aVal, int significantDigits, bool allowAbbreviate) { checked { string result; try { bool flag = double.IsNaN(aVal) || double.IsInfinity(aVal); if (flag) { result = ""; return result; } string text = "F" + significantDigits; //int length = ((long)Math.Round(Math.Ceiling(aVal))).ToString().Length; //string text = "###0.00"; //int num = significantDigits - 1; //int num2 = length + 2; //while (true) //{ // if (num2 > num) // { // break; // } // text += "0"; // num2++; //} if (allowAbbreviate) { result = GetAbbreviatedValueWithUnit(aVal, text); return result; } result = Strings.Format(aVal, text); return result; } catch { result = Strings.Format(aVal, "F2"); return result; } } } public static string GetAbbreviatedValueWithUnit(double aVal, string longFormat) { string result = Strings.Format(aVal, "0.00"); bool flag = Operators.CompareString(longFormat, "", false) != 0; if (flag) { try { result = Strings.Format(aVal, longFormat); } catch (Exception expr_56) { ProjectData.SetProjectError(expr_56); ProjectData.ClearProjectError(); } } var value = Math.Abs(aVal); if (value > 99999999) { result = Strings.Format(aVal / 100000000.0, "0.0") + LanguageManager.FindResource(LanguageConst.Currency_Unit_ThousandMillion); } else if (value > 9999999) { result = Strings.Format(aVal / 10000000, "0.0") + LanguageManager.FindResource(LanguageConst.Currency_Unit_TenMillion); } else if (value > 99999) { result = Strings.Format(aVal / 10000, "0.0") + LanguageManager.FindResource(LanguageConst.Currency_Unit_TenThousand); } return result; } //public static string GetAbbreviatedValue(double aVal, string longFormat) //{ // string result = Strings.Format(aVal, "0.00"); // bool flag = Operators.CompareString(longFormat, "", false) != 0; // if (flag) // { // try // { // result = Strings.Format(aVal, longFormat); // } // catch (Exception expr_56) // { // ProjectData.SetProjectError(expr_56); // ProjectData.ClearProjectError(); // } // } // flag = (Math.Abs(aVal) > 900000000000.0); // if (flag) // { // result = Strings.Format(aVal / 1000000000000.0, "0.0") + "T"; // } // else // { // flag = (Math.Abs(aVal) > 900000000.0); // if (flag) // { // result = Strings.Format(aVal / 1000000000.0, "0.0") + "B"; // } // else // { // flag = (Math.Abs(aVal) > 900000.0); // if (flag) // { // result = Strings.Format(aVal / 1000000.0, "0.0") + "M"; // } // else // { // flag = (Math.Abs(aVal) > 900.0); // if (flag) // { // result = Strings.Format(aVal / 1000.0, "0.0") + "K"; // } // } // } // } // return result; //} } }