【问题标题】:Including "and" word as a separator in ToWords function在 ToWords 函数中包含“and”作为分隔符
【发布时间】:2015-01-20 02:14:42
【问题描述】:

我正在使用 Crystal Report 中的 ToWords 函数将数字转换为单词。金额有时也可能包含小数,因此我包含了一个 IF 条件来评估它,仅在必要时才包含小数部分。

但是我还需要添加一个“和”词来分隔单词中的数量,以便于阅读。

例如。 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');

【问题讨论】:

  • 您要在tens 之前添加and 吗?
  • 不,它应该适用于像 130000 这样的数字,它只能读取 113000。如果无论数量多少,它都可以用于任何数量,那就太好了。这可能吗??
  • 对于任何单位(数百、数千、数百万等),您不能只检查该单位的百位和十位是否非零并在它们之间添加“和”如果是这样?。因此,在您的示例中,千位的百 (1) 位和十位 (30) 非零,因此您将添加一个“和”:130 万
  • This posting 建议只需要在数值中包含十进制值的情况下添加“and”即可。因此,1100 美元是“一千,一百美元”,而 100.10 美元是“一百美元和十美分”。如果它不是货币,我倾向于使用连字符并使用逗号:'55,123.35 = '五万五千,一百,二十三 POINT 三五。

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


【解决方案1】:

创建自定义函数:

//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)

【讨论】:

  • 您的自定义函数看起来很整洁,谢谢.. 但不幸的是我似乎无法使用它,当我尝试使用此函数并单击公式窗口上的保存时,VS 崩溃。 :( .. 无论如何我需要 Wordy(55123.00) 显示为 55123。而不是我已经默认获得的 55123
【解决方案2】:

这很棘手,但很简单...... 1. 将 38426 转换为 towords 函数的默认格式显示。 这被翻译为“三万八千四百二十六” 2.将此默认结果放入变量中,例如“txt” 3. 使用内部函数“替换”搜索“百”字,将其替换为“百和”。这解决了问题。

具体来说……

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 2018-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-10
    相关资源
    最近更新 更多