using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DSWeb.MvcShipping.Comm
{
///
/// 扩展Int32功能
///
public static class Int32Extensions
{
///
/// 向上整除
/// 1.当num能被divideBy整除时,结果即为num/divideBy;
/// 2.当num不能被divideBy整除时,结果为num/divideBy + 1;
///
/// 被除数,大于或者等于0
/// 除数,大于0
/// 向上整除结果
public static int CeilingDivide(this int num, int divideBy)
{
if (num < 0 || divideBy <= 0)
{
return 0;
}
return (num + divideBy - 1) / divideBy;
}
///
/// 向上整除
/// 1.当num能被divideBy整除时,结果即为num/divideBy;
/// 2.当num不能被divideBy整除时,结果为num/divideBy + 1;
///
/// 被除数,大于或者等于0
/// 除数,大于0
/// 向上整除结果
public static long CeilingDivide(this long num, long divideBy)
{
if (num < 0 || divideBy <= 0)
{
return 0;
}
return (num + divideBy - 1) / divideBy;
}
///
/// 将List 转为间隔字符串
///
///
public static string ListToString(this List strlist, char Split = ',')
{
StringBuilder str = new StringBuilder();
foreach (var item in strlist)
{
str.Append(item.ToString() + Split);
}
return str.ToString();
}
///
/// 拓展 将字符串抓换为int
///
///
///
public static int StrToInt(this string str)
{
if (str.Isint())
{ return Convert.ToInt32(str); }
else
{
return 0;
}
}
///
/// 拓展 将字符串数组转换成int 数组
///
///
///
public static int[] strToIntArray(this string[] str)
{
return Array.ConvertAll(str, new Converter(StrToInt));
}
}
}