| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- namespace Util
- {
- public class PublicFunction
- {
- public static decimal NumberFormat(decimal number, int floatCount = 2)
- {
- string str = number.ToString();
- if (str.Contains("."))
- {
- string[] list = str.Split('.');
- if (list[1].Length > floatCount)
- {
- str = list[0] + "." + list[1].Substring(0, floatCount);
- }
- }
- else
- {
- str += ".00";
- }
- return decimal.Parse(str);
- }
- #region 转换为首字母大写的驼峰格式
- public static string transferName(string name, int startUpperNum = 2)
- {
- if(string.IsNullOrEmpty(name))
- {
- return "";
- }
- string result = "";
- string[] list = name.Trim('_').Split('_');
- if(list.Length == 1)
- {
- if(startUpperNum == 1)
- {
- return name.Substring(0, 1).ToUpper() + name.Substring(1);
- }
- else if(startUpperNum > 1)
- {
- return name.Substring(0, 1).ToLower() + name.Substring(1);
- }
- else
- {
- return name;
- }
- }
- int index = 0;
- foreach(string sub in list)
- {
- index += 1;
- if(index >= startUpperNum)
- {
- result += sub.Substring(0, 1).ToUpper() + sub.Substring(1).ToLower();
- }
- else
- {
- result += sub.ToLower();
- }
- }
- if(startUpperNum > 1)
- {
- result = result.Substring(0, 1).ToLower() + result.Substring(1);
- }
- return result;
- }
- #endregion
-
-
- }
- }
|