string -> Fraction parsing now has error handling avoiding some problems

This commit is contained in:
N00MKRAD
2021-05-18 17:04:29 +02:00
parent 05a55fcbd5
commit 16b199f296
2 changed files with 56 additions and 30 deletions

View File

@@ -50,9 +50,27 @@ namespace Flowframes.Data
public Fraction(string text)
{
string[] numbers = text.Split('/');
Numerator = numbers[0].GetInt();
Denominator = numbers[1].GetInt();
try
{
string[] numbers = text.Split('/');
Numerator = numbers[0].GetInt();
Denominator = numbers[1].GetInt();
}
catch
{
try
{
Numerator = text.GetFloat().RoundToInt();
Denominator = 1;
}
catch
{
Numerator = 0;
Denominator = 0;
}
}
Logger.Log($"Fraction from String: Fraction(\"{text}\") => {Numerator}/{Denominator}", true);
}
private static int getGCD(int a, int b)