| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using Microsoft.VisualBasic;
- using Microsoft.VisualBasic.CompilerServices;
- using System;
- namespace MuchInfo.Chart.WPF.Helpers
- {
- public class TextFormatting
- {
- /// <summary>
- /// Formats the number.
- /// </summary>
- /// <param name="aVal">A value.</param>
- /// <param name="significantDigits">The significant digits.</param>
- /// <param name="allowAbbreviate">if set to <c>true</c> [allow abbreviate].</param>
- /// <returns>System.Object.</returns>
- 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;
- //}
- }
- }
|