Fix Index out of range in .ToDisplayString()

This commit is contained in:
ig 2023-08-17 08:01:16 +02:00
parent 2047f25e4e
commit ed39b8e847
1 changed files with 4 additions and 2 deletions

View File

@ -19,12 +19,12 @@ public abstract class Unit
var i = 8; var i = 8;
while (a >= 10000) while (a >= 10000 && i < MaxPrefix)
{ {
a /= 1000; a /= 1000;
i++; i++;
} }
while (a < 10) while (a < 10 && i > 0)
{ {
a *= 1000; a *= 1000;
i--; i--;
@ -38,5 +38,7 @@ public abstract class Unit
} }
private static readonly IReadOnlyList<String> Prefix = new[] { "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Y" }; private static readonly IReadOnlyList<String> Prefix = new[] { "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Y" };
private static Int32 MaxPrefix { get; } = Prefix.Count - 1;
} }