-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utility.cs
47 lines (31 loc) · 1.02 KB
/
Utility.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using BetterConsoleTables;
using static ResistorSearch.Solver;
namespace ResistorSearch;
public class Utility {
static public void WriteInfo(List<Info> infoList, int max = 200) {
var table = new Table("Vout", "R1", "R2");
foreach (var info in infoList) {
table.AddRow(
info.v.ToString("F" + "2".PadLeft(2, '0')).Replace(",", "."),
FormatResistance(info.x),
FormatResistance(info.y)
);
if (--max <= 0) {
break;
}
}
table.Config = TableConfiguration.MySql();
Console.Write(table.ToString());
}
static public string FormatResistance(double ohms) {
string res;
if (ohms >= 1_000_000) {
res = $"{Math.Round(ohms / 1_000_000, 2)}M";
} else if(ohms >= 1_000) {
res = $"{Math.Round(ohms / 1_000, 2)}k";
} else {
res = $"{Math.Round(ohms, 2)}";
}
return res.Replace(",", ".");
}
}