/// <summary>【通用函数】取得金额某位的大写</summary> /// <param name="Value">数字</param> /// <param name="B">位置,-2分-1角0元1十2百3千4万,以此类推</param> /// <returns>返回数字,如:贰</returns> public static string MoneyBitUpper(double Value, int B) { const string NUM = "零壹贰叁肆伍陆柒捌玖"; string S = ""; double d = StrToDouble(Value.ToString("0.00")); if (d < 0) { S = "负"; d = -d; } int P = (int)(d / Math.Pow(10, B) + 0.001); if (P == 0) { return("¤"); } else { if (P >= 10) { S = ""; } P = P % 10; return(S + NUM.Substring(P, 1)); } }
///// <summary>【通用函数】FONT转STRING ///// </summary> //public static string FontToStr(Font aFont) //{ // FontConverter fc = new FontConverter(); // return fc.ConvertToInvariantString(aFont); //} ///// <summary>【通用函数】STRING转FONT ///// </summary> //public static Font StrToFont(string aStr) //{ // FontConverter fc = new FontConverter(); // Font f = (Font)fc.ConvertFromString(aStr); // return f; //} /// <summary>【通用函数】金额小写转换成大写</summary> /// <param name="Value">数字</param> /// <param name="AState">状态,true表示完整,false表示简写</param> /// <returns>返回字符串,如:叁佰贰拾伍元整</returns> public static string MoneyToUpper(double Value, bool AState) { const string NUM = "零壹贰叁肆伍陆柒捌玖"; const string WEI = "分角元拾佰仟万拾佰仟亿拾佰仟"; string F = ""; double d = StrToDouble(Value.ToString("0.00")); if (AState) { if (d < 0) { d = -d; F = "负"; } else if (d == 0) { F = "零元零角零分"; } else { F = ""; } int L = (int)Math.Truncate(Math.Log(d, 10)); string Str = ""; for (int i = L; i >= -2; i--) { Int64 T = (Int64)(Math.Round(d, 2) / Math.Pow(10, i) + 0.000001); int N = (int)(T % 10); Str = Str + NUM.Substring(N, 1) + WEI.Substring(i + 2, 1); } Str = F + Str; return(Str); } else { if (d < 0) { d = -d; F = "负"; } else if (d == 0) { F = "零元整"; } else { F = ""; } int L = (int)(Math.Floor(Math.Log(d + 0.0000001, 10))); string Str = ""; bool Zero = false; //上一位是不是0 for (int i = L; i >= -2; i--) { Int64 T = (Int64)(Math.Round(d, 2) / Math.Pow(10, i) + 0.000001); int N = (int)(T % 10); if (N == 0) { if (i == 0 || i == 4 || i == 8) //碰到元、万、亿必须显示 { Str = Str + WEI.Substring(i + 2, 1); Zero = false; } else { Zero = true; } } else { if (Zero) { Str = Str + NUM.Substring(0, 1); } Str = Str + NUM.Substring(N, 1) + WEI.Substring(i + 2, 1); Zero = false; } if (Math.Abs(d - T * Math.Pow(10, i)) < 0.001 && i > -2 && i < 5) { if (i > 0) { Str = Str + "元整"; } else { Str = Str + "整"; } break; } } Str = F + Str; return(Str); } }