Skip to content

Commit

Permalink
Merge pull request #2163 from Michael-Kowata/main
Browse files Browse the repository at this point in the history
Fix TryParse method in Percent.cs
  • Loading branch information
Al12rs authored Oct 14, 2024
2 parents bd7aae4 + c81f5b3 commit 1b2caea
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace NexusMods.Abstractions.Activities;
using System.Globalization;

/// <summary>
/// Represents a percentage; used for reporting progress of various operations
Expand Down Expand Up @@ -152,7 +153,10 @@ public int CompareTo(object? obj)
/// <returns></returns>
public static bool TryParse(string str, out Percent p)
{
// TODO: This will not parse a value like 3.33%, as `TryParse` will not accept % suffix. https://github.com/Nexus-Mods/NexusMods.App/issues/209
var strSpan = str.AsSpan();
if (strSpan[^1] == NumberFormatInfo.CurrentInfo.PercentSymbol[0])
strSpan = strSpan[..^1];

if (double.TryParse(str, out var d))
{
d /= 100;
Expand Down

0 comments on commit 1b2caea

Please sign in to comment.