using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using MyCode.Project.Infrastructure.Extensions; namespace MyCode.Project.Infrastructure.Format { public static class Money { /// /// 保留两位小数,四舍五入 /// public static string ToTwoPoint(this decimal value) { return value.ToString("f2"); } /// /// 保留两位小数,不四舍五入 /// /// /// /// public static decimal CutDecimalWithN(decimal d, int n) { string strDecimal = d.ToString(); int index = strDecimal.IndexOf("."); if (index == -1 || strDecimal.Length < index + n + 1) { strDecimal = string.Format("{0:F" + n + "}", d); } else { int length = index; if (n != 0) { length = index + n + 1; } strDecimal = strDecimal.Substring(0, length); } return Decimal.Parse(strDecimal); } } }