V1.2 新构架

This commit is contained in:
Aigio Liu
2021-02-20 16:45:44 +08:00
parent c2d95a1833
commit 4d76decf73
343 changed files with 41333 additions and 4 deletions
@@ -0,0 +1,52 @@
namespace System
{
/// <summary>
/// 小数数字转换为整数数字格式
/// </summary>
public enum NumberToInt32Format
{
/// <summary>
/// 四舍五入
/// </summary>
RoundAwayFromZero,
/// <summary>
/// 五舍六入
/// </summary>
Round,
/// <summary>
/// 仅取整数
/// </summary>
Floor,
/// <summary>
/// 进一法
/// </summary>
Ceiling,
}
/// <summary>
/// Enum 扩展 <see cref="NumberToInt32Format"/>
/// </summary>
public static partial class NumberToInt32FormatEnumExtensions
{
public static int ToInt32(this float value, NumberToInt32Format format = NumberToInt32Format.Floor) => format switch
{
NumberToInt32Format.RoundAwayFromZero => (int)MathF.Round(value, MidpointRounding.AwayFromZero),
NumberToInt32Format.Round => (int)MathF.Round(value),
NumberToInt32Format.Floor => (int)MathF.Floor(value),
NumberToInt32Format.Ceiling => (int)MathF.Ceiling(value),
_ => throw new ArgumentOutOfRangeException(nameof(format), format, null),
};
public static int ToInt32(this double value, NumberToInt32Format format = NumberToInt32Format.Floor) => format switch
{
NumberToInt32Format.RoundAwayFromZero => (int)Math.Round(value, MidpointRounding.AwayFromZero),
NumberToInt32Format.Round => (int)Math.Round(value),
NumberToInt32Format.Floor => (int)Math.Floor(value),
NumberToInt32Format.Ceiling => (int)Math.Ceiling(value),
_ => throw new ArgumentOutOfRangeException(nameof(format), format, null),
};
}
}