}
4:判断数字之间是否有跳位,也就是中文中间是否要加零,例如1020 就应该加零。
/// <summary>
/// 是否跳位
/// </summary>
/// <returns></returns>
private bool IsDumpLevel(double Num)
{
if (Num > 0)
{
NumLevel? currentLevel = GetNumLevel(Num);
NumLevel? nextLevel = null;
int numExponent = this.NumLevelExponent[(int)currentLevel];
double postfixNun = Math.Round(Num % (Math.Pow(10, numExponent)),2);
if(postfixNun> 0)
nextLevel = GetNumLevel(postfixNun);
if (currentLevel != null && nextLevel != null)
{
if (currentLevel > nextLevel + 1)
{
return true;
}
}
}
return false;
}
5 把长数字分割为两个较小的数字数组,例如把9999亿兆,分割为9999亿和0兆,
因为计算机不支持过长的数字。
/// <summary>
/// 是否大于兆,如果大于就把字符串分为两部分,
/// 一部分是兆以前的数字
/// 另一部分是兆以后的数字
/// </summary>
/// <param name="Num"></param>
/// <returns></returns>
private bool IsBigThanTillion(string Num)
{
bool isBig = false;
if (Num.IndexOf(''.'') != -1)
{
//如果大于兆
if (Num.IndexOf(''.'') > NumLevelExponent[(int)NumLevel.Trillion])
{
isBig = true;
}
}
else
{
//如果大于兆
if (Num.Length > NumLevelExponent[(int)NumLevel.Trillion])
{
isBig = true;
}
}
return isBig;
}
/// <summary>
/// 把数字字符串由‘兆’分开两个
/// </summary>
/// <returns></returns>
private double SplitNum(string Num)
{
//兆的开始位
double TillionLevelNums = new double;
int trillionLevelLength;
if (Num.IndexOf(''.'') == -1)
trillionLevelLength = Num.Length - NumLevelExponent[(int)NumLevel.Trillion];
else
trillionLevelLength = Num.IndexOf(''.'') - NumLevelExponent[(int)NumLevel.Trillion];
//兆以上的数字
TillionLevelNums[0] = Convert.ToDouble(Num.Substring(0, trillionLevelLength));
//兆以下的数字
TillionLevelNums = Convert.ToDouble(Num.Substring(trillionLevelLength ));
return TillionLevelNums;
}
6 是否以“壹拾”开头,如果是就可以把它变为“拾”
bool isStartOfTen = false;
while (Num >=10)
{
if (Num == 10)
{
isStartOfTen = true;
break;
}
//Num的数位
NumLevel currentLevel = GetNumLevel(Num);
int numExponent = this.NumLevelExponent[(int)currentLevel];
Num = Convert.ToInt32(Math.Floor(Num / Math.Pow(10, numExponent)));
if (currentLevel == NumLevel.Ten && Num == 1)
{
isStartOfTen = true;
break;
}
}
return isStartOfTen;
7 合并大于兆连个数组转化成的货币字符串
/// <summary>
/// 合并分开的数组中文货币字符
/// </summary>
/// <param name="tillionNums"></param>
/// <returns></returns>
private string ContactNumChinese(double tillionNums)
{
string uptillionStr = CalculateChineseSign(tillionNums[0], NumLevel.Trillion, true, IsStartOfTen(tillionNums[0]));
string downtrillionStr = CalculateChineseSign(tillionNums, null, true,false);
string chineseCharactor = string.Empty;
//分开后的字符是否有跳位
if (GetNumLevel(tillionNums *