不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
金额大小写转化类
编辑:dnawo 日期:2009-05-13
复制内容到剪贴板
程序代码

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
/// <summary>
/// 类 名: MoneyHelper
/// 版 本 号: V1.0
/// 作 者: 张远强
/// HomePage: http://www.mzwu.com/
/// 创建日期: 2009-05-12
/// 功能描述: 金额大小写转化类
/// </summary>
public sealed class MoneyHelper
{
/// <summary>
/// 转为小写金额
/// </summary>
/// <param name="money">大写金额</param>
/// <returns></returns>
public static double ToLower(string money)
{
return ToLowerForInt(money) + ToLowerForDec(money);
}
/// <summary>
/// 转为小写金额(整数)
/// </summary>
/// <param name="money">大写金额</param>
/// <returns></returns>
private static double ToLowerForInt(string money)
{
string[] units = new string[] { "亿", "万", "千", "百", "十", "元" };//金额单位数组
int[] indexs = new int[] { 8, 4, 3, 2, 1, 0 };//金额单位对应位数,如亿位于第8位,百位于第2位,元位于第0位
string[] items = new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };//十个基本数字(大写)
double[] results = new double[indexs[0] + indexs[1] + 2];//保存结果,其长度为最大的两个单位位数之和+1
//特殊处理:以十开头的大写金额前一律加上"一".我们平时说十万表示一十万,十表示一十,但不会有人说百万,千亿
if (money.Substring(0, 1) == "十")
money = "一" + money;
//只处理整数部分
if (money.IndexOf("元") != -1)
{
money = money.Split('元')[0] + "元";
}
else
{
money = money.TrimEnd('元') + "元";
}
//临时数组
string[] temps = new string[2] { "", money };
//按金额单位从大到小循环处理(精确到元)
for (int i = 0; i < units.Length; i++)
{
if (string.IsNullOrEmpty(temps[1]))
{
break;
}
else
{
if (temps[1].IndexOf(units[i]) != -1)
{
//在单位处切割
temps = temps[1].Split(new string[] { units[i] }, StringSplitOptions.None);
//对左部分再按金额单位从大到小循环处理(精确到元)
temps[0] += "元";
for (int j = i; j < units.Length; j++)
{
Match match = Regex.Match(temps[0], string.Format("([{0}]{{1}}){1}", string.Concat(items), units[j]), RegexOptions.IgnoreCase);
if (match.Success)
{
results[results.Length-(indexs[i]+indexs[j]+1)] = Convert.ToDouble(string.Concat(items).IndexOf(match.Groups[1].ToString()));
}
}
}
}
}
//将results数组元素按权相加为数字
double r = 0;
for (int i = results.Length - 1; i >= 0; i--)
{
r += results[i] * Math.Pow(10, results.Length - i - 1);
}
return r;
}
/// <summary>
/// 转为小写金额(小数)
/// </summary>
/// <param name="money">大写金额</param>
/// <returns></returns>
private static double ToLowerForDec(string money)
{
string[] units = new string[] { "角", "分", "厘", "毫" };//金额单位数组
int[] indexs = new int[] { 3, 2, 1, 0 };//金额单位对应位数
string[] items = new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };//十个基本数字(大写)
double[] results = new double[4];//保存结果
//只处理小数部分
if (money.IndexOf("元") != -1)
money = money.Split('元')[1];
//循环处理各位
for (int i = 0; i < units.Length; i++)
{
Match match = Regex.Match(money, string.Format("([{0}]{{1}}){1}", string.Concat(items), units[i]), RegexOptions.IgnoreCase);
if (match.Success)
{
results[results.Length - (indexs[i] + 1)] = Convert.ToDouble(string.Concat(items).IndexOf(match.Groups[1].ToString()));
}
}
//将results数组元素按权相加为数字
double r = 0;
for (int i = 0; i < results.Length;i++ )
{
r += results[i] * Math.Pow(10, -(i + 1));
}
return r;
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
/// <summary>
/// 类 名: MoneyHelper
/// 版 本 号: V1.0
/// 作 者: 张远强
/// HomePage: http://www.mzwu.com/
/// 创建日期: 2009-05-12
/// 功能描述: 金额大小写转化类
/// </summary>
public sealed class MoneyHelper
{
/// <summary>
/// 转为小写金额
/// </summary>
/// <param name="money">大写金额</param>
/// <returns></returns>
public static double ToLower(string money)
{
return ToLowerForInt(money) + ToLowerForDec(money);
}
/// <summary>
/// 转为小写金额(整数)
/// </summary>
/// <param name="money">大写金额</param>
/// <returns></returns>
private static double ToLowerForInt(string money)
{
string[] units = new string[] { "亿", "万", "千", "百", "十", "元" };//金额单位数组
int[] indexs = new int[] { 8, 4, 3, 2, 1, 0 };//金额单位对应位数,如亿位于第8位,百位于第2位,元位于第0位
string[] items = new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };//十个基本数字(大写)
double[] results = new double[indexs[0] + indexs[1] + 2];//保存结果,其长度为最大的两个单位位数之和+1
//特殊处理:以十开头的大写金额前一律加上"一".我们平时说十万表示一十万,十表示一十,但不会有人说百万,千亿
if (money.Substring(0, 1) == "十")
money = "一" + money;
//只处理整数部分
if (money.IndexOf("元") != -1)
{
money = money.Split('元')[0] + "元";
}
else
{
money = money.TrimEnd('元') + "元";
}
//临时数组
string[] temps = new string[2] { "", money };
//按金额单位从大到小循环处理(精确到元)
for (int i = 0; i < units.Length; i++)
{
if (string.IsNullOrEmpty(temps[1]))
{
break;
}
else
{
if (temps[1].IndexOf(units[i]) != -1)
{
//在单位处切割
temps = temps[1].Split(new string[] { units[i] }, StringSplitOptions.None);
//对左部分再按金额单位从大到小循环处理(精确到元)
temps[0] += "元";
for (int j = i; j < units.Length; j++)
{
Match match = Regex.Match(temps[0], string.Format("([{0}]{{1}}){1}", string.Concat(items), units[j]), RegexOptions.IgnoreCase);
if (match.Success)
{
results[results.Length-(indexs[i]+indexs[j]+1)] = Convert.ToDouble(string.Concat(items).IndexOf(match.Groups[1].ToString()));
}
}
}
}
}
//将results数组元素按权相加为数字
double r = 0;
for (int i = results.Length - 1; i >= 0; i--)
{
r += results[i] * Math.Pow(10, results.Length - i - 1);
}
return r;
}
/// <summary>
/// 转为小写金额(小数)
/// </summary>
/// <param name="money">大写金额</param>
/// <returns></returns>
private static double ToLowerForDec(string money)
{
string[] units = new string[] { "角", "分", "厘", "毫" };//金额单位数组
int[] indexs = new int[] { 3, 2, 1, 0 };//金额单位对应位数
string[] items = new string[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };//十个基本数字(大写)
double[] results = new double[4];//保存结果
//只处理小数部分
if (money.IndexOf("元") != -1)
money = money.Split('元')[1];
//循环处理各位
for (int i = 0; i < units.Length; i++)
{
Match match = Regex.Match(money, string.Format("([{0}]{{1}}){1}", string.Concat(items), units[i]), RegexOptions.IgnoreCase);
if (match.Success)
{
results[results.Length - (indexs[i] + 1)] = Convert.ToDouble(string.Concat(items).IndexOf(match.Groups[1].ToString()));
}
}
//将results数组元素按权相加为数字
double r = 0;
for (int i = 0; i < results.Length;i++ )
{
r += results[i] * Math.Pow(10, -(i + 1));
}
return r;
}
}
}
评论: 0 | 引用: 0 | 查看次数: 4217
发表评论
请登录后再发表评论!