包括"和"单词作为ToWords函数中的分隔符

时间:2014-12-08 11:24:27

标签: crystal-reports crystal-reports-2008 crystal-reports-xi crystal-reports-2010

我在Crystal Report中使用ToWords功能将数字转换为单词。金额有时也可能包含十进制值,因此我已经包含一个IF条件来评估它只在必要时包括小数部分。

但是我还需要添加一个“和”单词来分隔单词中的金额,以便更容易阅读。

对于Eg。 38426应显示为“三万八千二百四十六”。此刻的内容为“三万八千二百四十六”。

这是我目前的代码。

    NUMBERVAR amount    := 38246;
    NUMBERVAR decimals  := (Round(amount,2) - Int(amount)) * 100;
    STRINGVAR words     := 'Rupees';

    words := words & ' ' & TOWORDS(amount,0);

    IF(decimals > 0) THEN words := words & ' and ' &TOWORDS(decimals,0) & ' cents';

    words := PROPERCASE(words & ' only');

2 个答案:

答案 0 :(得分:2)

创建自定义函数:

//Wordy()
Function (Numbervar Value)

If Remainder(Value,1)=0 Then
    ProperCase(ToWords(Value,0)) + " Dollars"
Else
    Replace(Replace(ProperCase(ToWords(Value,2)), "And", "Dollars And"), "/ 100", "Cents")

在公式字段中使用函数:

// Fifty-Five Thousand One Hundred Twenty-Three Dollars
Wordy(55123.00)

// Fifty-Five Thousand One Hundred Twenty-Three Dollars And 55 Cents
Wordy(55123.55)

答案 1 :(得分:0)

这很棘手但很简单...... 1.转换38426以拖曳功能的默认格式显示。 这被呈现为"三十八万四千二百六十四" 2.将此默认结果放入变量say" txt" 3.使用内部功能"替换"搜索单词" Hundred"并将其替换为"百和"。这解决了这个问题。

实际细节......

currencyvar tt; 
currencyvar dect; 
stringvar txt;
tt := 38426 ; 
dect := tt - Truncate(tt); 
tt := truncate(tt); 
dect := dect * 100; 
if dect = 0 then //default format 

ProperCase (ToWords (tt,0 ) + ' Dollars Only' ) // without decimal (cents)
else 

txt := ProperCase (ToWords (tt,0) + ' Dollars, ' + ToWords(dect,0) + ' cents Only'); 

//include "and"
Replace (txt,"Hundred" ,"Hundred and" )

编辑: 以上是对此处发现的解决方案的改进 http://www.c-sharpcorner.com/forums/thread/235835/number-to-words-in-crystal-report.aspx

相关问题