50金币
本帖最后由 CainduranceTX 于 2023-10-9 11:03 编辑
如图,上图的达表示结算的结果为空时,如何让红框里显示数字0,让黄框里不显示内容。
红框里的表达式为:{Sum(大病支付, "大病保险明细门诊")}
黄框里的表达式为:{Code.ConvertToCNYText(Sum(大病支付, "大病保险明细门诊"))} 用的是自定义的小写转汉字大写的函数,论坛抄的,函数如下:
/// <function name="ConvertToCNYText">
/// <culture>
/// <label>ConvertToCNYText</label>
/// <syntax>ConvertToCNYText(string inputString)</syntax>
/// <description>自动转换中文单位</description>
/// <example>ConvertToCNYText("100") = 壹佰元整
/// </example>
/// </culture>
/// </function>
///
public string ConvertToCNYText(string inputString)
{
try
{
string numList = "零壹贰叁肆伍陆柒捌玖";
string rmbList = "分角元拾佰仟万拾佰仟亿拾佰仟万";
double number = 0;
string tempOutString = "";
number = double.Parse(inputString);
string tempNumberString = Convert.ToInt64(number * 100).ToString();
int tempNmberLength = tempNumberString.Length;
int i = 0;
while (i < tempNmberLength)
{
int oneNumber = Int32.Parse(tempNumberString.Substring(i, 1));
string oneNumberChar = numList.Substring(oneNumber, 1);
string oneNumberUnit = rmbList.Substring(tempNmberLength - i - 1, 1);
if (!(oneNumberChar == "零"))
tempOutString += oneNumberChar + oneNumberUnit;
else
{
if (oneNumberUnit == "亿" || oneNumberUnit == "万" || oneNumberUnit == "元" || oneNumberUnit == "零")
{
while (tempOutString.EndsWith("零"))
tempOutString = tempOutString.Substring(0, tempOutString.Length - 1);
}
if (oneNumberUnit == "亿" || (oneNumberUnit == "万" && !tempOutString.EndsWith("亿")) || oneNumberUnit == "元")
tempOutString += oneNumberUnit;
else if (tempOutString != null)
{
bool tempEnd = tempOutString.EndsWith("亿");
bool zeroEnd = tempOutString.EndsWith("零");
if (tempOutString.Length > 1)
{
bool zeroStart = tempOutString.Substring(tempOutString.Length - 2, 2).StartsWith("零");
if (!zeroEnd && (zeroStart || !tempEnd))
tempOutString += oneNumberChar;
}
else if (!zeroEnd && !tempEnd)
tempOutString += oneNumberChar;
}
}
i += 1;
}
if (tempOutString != null)
{
while (tempOutString.EndsWith("零"))
tempOutString = tempOutString.Substring(0, tempOutString.Length - 1);
while (tempOutString.EndsWith("元"))
tempOutString = tempOutString + "整";
return tempOutString;
}
}
catch (Exception ex)
{
return "#数值转换错误" + ex.Message;
}
return String.Empty;
}
/// <function name="UserFunction">
/// <culture>
/// <label>UserFunction</label>
/// <syntax>UserFunction(<ArgumentName>)</syntax>
/// <description>自定义函数描述</description>
/// <example>Code.UserFunction("ArgumentValue")</example>
/// </culture>
/// </function>
public string UserFunction(string argumentName)
{
return argumentName;
}
|
-
最佳答案
查看完整内容
您好,您的问题描述如下,您看看:
问题描述:报表的空值显示0,使用自定义函数转换大小写的值若转换错误,显示空白
问题解答:
这2个问题都需要使用IIF函数来判断,IIF函数语法:{IIF(表达式,true,false)}
|