80 lines
2.0 KiB
C#
80 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using CsharpHttpHelper;
|
|
|
|
namespace Api.Framework.Extents
|
|
{
|
|
/// <summary>
|
|
/// 数值相关扩展类
|
|
/// </summary>
|
|
public static class ValueEx
|
|
{
|
|
|
|
/// <summary>
|
|
/// 执行除法
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static double ExecDivision(this int value, double divisor = 100d, int decimals = 2)
|
|
{
|
|
if (value == 0) return 0;
|
|
|
|
return (double)((decimal)value / (decimal)divisor).ToDecimal(decimals);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行除法
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static double ExecDivision(this double value, double divisor = 100d, int decimals = 2)
|
|
{
|
|
if (value == 0) return 0;
|
|
|
|
return (double)((decimal)value / (decimal)divisor).ToDecimal(decimals);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行除法
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static decimal ExecDivision(this decimal value, decimal divisor = 100m, int decimals = 2)
|
|
{
|
|
if (value == 0) return 0;
|
|
|
|
return (value / divisor).ToDecimal(decimals);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转为指定的小数位
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
/// <param name="decimals"></param>
|
|
/// <returns></returns>
|
|
public static decimal ToDecimal(this decimal value, int decimals = 2)
|
|
{
|
|
return Math.Round(value, decimals);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 时间戳转时间
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
public static DateTime ToDateTime(this long value)
|
|
{
|
|
try
|
|
{
|
|
return HttpExtend.GetDateTime(value.ToString());
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return DateTime.MinValue;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|