Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3140_NumberSymbol/HeuristicLab.ExtLibs/HeuristicLab.SimSharp/3.3.2/SimSharp-3.3.2/Auxiliary/Formatter.cs @ 18190

Last change on this file since 18190 was 18023, checked in by jkarder, 3 years ago

#3065: update Sim# to 3.3.2

File size: 1.6 KB
Line 
1using System;
2
3namespace 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}
Note: See TracBrowser for help on using the repository browser.