[18023] | 1 | using System; |
---|
| 2 | |
---|
| 3 | namespace SimSharp { |
---|
| 4 | public static class Formatter { |
---|
| 5 | public static string Format12(double number, bool silenceNaN = true) { |
---|
| 6 | if (double.IsNaN(number)) return silenceNaN ? " " : " nan "; |
---|
| 7 | if (number >= 1e7 || number <= -1e7) { |
---|
| 8 | if (number >= 1e100 || number <= -1e100) return string.Format("{0,12:0.####E+000}", number); |
---|
| 9 | return string.Format("{0,12:0.#####E+00}", number); |
---|
| 10 | } |
---|
| 11 | if (Math.Abs(number) < 1e-3) { |
---|
| 12 | if (number == 0) return " 0 "; |
---|
| 13 | if (Math.Abs(number) <= 1e-100) { |
---|
| 14 | return string.Format("{0,12:0.####E-000}", number); |
---|
| 15 | } |
---|
| 16 | return string.Format("{0,12:0.#####E-00}", number); |
---|
| 17 | } |
---|
| 18 | if (number == (int)number) return string.Format("{0,8} ", (int)number); |
---|
| 19 | return string.Format("{0,12}", number.ToString("0.000")); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | public static string Format15(double number, bool silenceNaN = true) { |
---|
| 23 | if (double.IsNaN(number)) return silenceNaN ? " " : " nan "; |
---|
| 24 | if (number >= 1e10 || number <= -1e10) { |
---|
| 25 | if (number >= 1e100 || number <= -1e100) return string.Format("{0,15:0.#######E+000}", number); |
---|
| 26 | return string.Format("{0,15:0.########E+00}", number); |
---|
| 27 | } |
---|
| 28 | if (Math.Abs(number) < 1e-3) { |
---|
| 29 | if (number == 0) return " 0 "; |
---|
| 30 | if (Math.Abs(number) <= 1e-100) { |
---|
| 31 | return string.Format("{0,15:0.#######E-000}", number); |
---|
| 32 | } |
---|
| 33 | return string.Format("{0,15:0.########E-00}", number); |
---|
| 34 | } |
---|
| 35 | if (number == (int)number) return string.Format("{0,11} ", (int)number); |
---|
| 36 | return string.Format("{0,15}", number.ToString("0.000")); |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | } |
---|