core-build
This commit is contained in:
63
src/WMS.Web.Core/NumericalProcess.cs
Normal file
63
src/WMS.Web.Core/NumericalProcess.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 数值处理
|
||||
/// </summary>
|
||||
public static class NumericalProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// Decimal 数值精度转换
|
||||
/// </summary>
|
||||
/// <param name="number"> decimal数值</param>
|
||||
/// <param name="precision">精度值</param>
|
||||
/// <param name="RoundoffType"> 舍入类型:1为进位,2为舍位,3为四舍五入</param>
|
||||
/// <returns>decimal数值</returns>
|
||||
public static decimal DecimalPrecision(this decimal? number, int? precision, int? RoundoffType)
|
||||
{
|
||||
if (RoundoffType == 1)
|
||||
return Decimal.Round(number ?? 0, precision ?? 0, MidpointRounding.ToPositiveInfinity);
|
||||
else if (RoundoffType == 2)
|
||||
return Decimal.Round(number ?? 0, precision ?? 0, MidpointRounding.ToZero);
|
||||
else if (RoundoffType == 3)
|
||||
return Decimal.Round(number ?? 0, precision ?? 0, MidpointRounding.AwayFromZero);
|
||||
return number ?? 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decimal 数值精度转换
|
||||
/// </summary>
|
||||
/// <param name="number"> decimal数值</param>
|
||||
/// <param name="precision">精度值</param>
|
||||
/// <param name="RoundoffType"> 舍入类型:1为进位,2为舍位,3为四舍五入</param>
|
||||
/// <returns>decimal数值</returns>
|
||||
public static decimal DecimalPrecision(this decimal number, int? precision, int? RoundoffType)
|
||||
{
|
||||
if (RoundoffType == 1)
|
||||
return Decimal.Round(number, precision ?? 0, MidpointRounding.ToPositiveInfinity);
|
||||
else if (RoundoffType == 2)
|
||||
return Decimal.Round(number, precision ?? 0, MidpointRounding.ToZero);
|
||||
else if (RoundoffType == 3)
|
||||
return Decimal.Round(number, precision ?? 0, MidpointRounding.AwayFromZero);
|
||||
return number;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decimal 去掉后面无效的0
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public static string DecimalToStringNoZero(this decimal? data)
|
||||
{
|
||||
return (data ?? 0).ToString("#0.##########");
|
||||
}
|
||||
|
||||
public static string DecimalToStringNoZero(this decimal data)
|
||||
{
|
||||
return data.ToString("#0.##########");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user