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