Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'UVtools.Core/Extensions/MathExtensions.cs')
-rw-r--r--UVtools.Core/Extensions/MathExtensions.cs6
1 files changed, 5 insertions, 1 deletions
diff --git a/UVtools.Core/Extensions/MathExtensions.cs b/UVtools.Core/Extensions/MathExtensions.cs
index 2020744..4bb6c92 100644
--- a/UVtools.Core/Extensions/MathExtensions.cs
+++ b/UVtools.Core/Extensions/MathExtensions.cs
@@ -103,12 +103,16 @@ namespace UVtools.Core.Extensions
public static uint DecimalDigits(this decimal val)
{
var valStr = val.ToString(CultureInfo.InvariantCulture).TrimEnd('0');
- if (string.IsNullOrEmpty(valStr) || valStr[valStr.Length-1] == '.') return 0;
+ if (string.IsNullOrEmpty(valStr) || valStr[^1] == '.') return 0;
var index = valStr.IndexOf('.');
if (index < 0) return 0;
return (uint)(valStr.Substring(index).Length - 1);
}
+
+ public static bool IsInteger(this float val, float tolerance = 0.0001f) => Math.Abs(val - Math.Floor(val)) < tolerance;
+ public static bool IsInteger(this double val, double tolerance = 0.0001) => Math.Abs(val - Math.Floor(val)) < tolerance;
+ public static bool IsInteger(this decimal val) => val == Math.Floor(val);
}
}