| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | using System;
|
| | using System.Globalization;
|
| |
|
| | namespace SwarmOps
|
| | {
|
| | public static partial class Tools
|
| | {
|
| | private static CultureInfo _cultureInfo = new CultureInfo("en-US");
|
| |
|
| |
|
| |
|
| |
|
| | public static string FormatNumber(double? d)
|
| | {
|
| | string s;
|
| |
|
| | if (d.HasValue)
|
| | {
|
| | double dAbs = Math.Abs(d.Value);
|
| |
|
| | if (dAbs < 1e-2)
|
| | {
|
| | s = String.Format(_cultureInfo, "{0:0.##e0}", d.Value);
|
| | }
|
| | else if (dAbs > 1e+6)
|
| | {
|
| | s = String.Format(_cultureInfo, "{0:0.##e+0}", d.Value);
|
| | }
|
| | else if (dAbs > 1e+3)
|
| | {
|
| | s = String.Format(_cultureInfo, "{0:0.}", d.Value);
|
| | }
|
| | else
|
| | {
|
| | s = String.Format(_cultureInfo, "{0:0.##}", d.Value);
|
| | }
|
| | }
|
| | else
|
| | {
|
| | s = "--";
|
| | }
|
| |
|
| | return s;
|
| | }
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | public static string FormatPercent(double? d)
|
| | {
|
| | return String.Format(_cultureInfo, "{0:0.##}%", d*100);
|
| | }
|
| | }
|
| | }
|
| |
|