简体   繁体   English

将Crystal报告运行总字符串转换为数字时出现问题

[英]Problems converting a crystal reports running total string to a number

I have a problem with converting a running totals string to a number. 将运行中的总计字符串转换为数字时遇到问题。

The running total is set to retrieve the maximum value of a field that contains results. 设置运行总计以检索包含结果的字段的最大值。 It is reset with change of a group and evaluated by a formula so that only results from a specific test is used. 更改组后将其重置,并通过公式进行评估,以便仅使用特定测试的结果。
The result database field is a string since there are test with text results as well as tests with numeric results in the database. 结果数据库字段是一个字符串,因为数据库中存在文本结果测试和数字结果测试。 The test I'm filtering out only have numeric results (saved as string). 我过滤掉的测试只有数字结果(保存为字符串)。

The running total works fine and gives the correct result, but I want to change it from a string to a number to be able to set the number of decimals and use rounding in the report, and this is where my problem begins. 运行总计工作正常并给出正确的结果,但是我想将其从字符串更改为数字,以便能够设置小数位数并在报告中使用四舍五入,这就是我的问题所在。

  • As far as I can tell there is no way of using the format field in this case. 据我所知,在这种情况下无法使用格式字段。 (Which is resonable since it is a string field.) (由于这是一个字符串字段,因此比较合理。)
  • I've tried using a formula field with the following formula: 我尝试将公式字段与以下公式一起使用:

     if isNumeric({#P-LDL}) then toNumber({#P-LDL}) 

    but that returns 0.00 for all non-null values even though the strings are nice things like "2.36" or "3.74" (without the quotes). 但是,即使字符串是“ 2.36”或“ 3.74”之类的好东西(不带引号),对于所有非空值也返回0.00。

  • I've also tried the old school approach of resetting a global variable in the group head, assigning it a value in the details section when a post with the correct test comes along, and then finally display it in the group footer, but I get the same 0.00 result. 我还尝试了一种古老的方法,即在组头中重置全局变量,在发布具有正确测试的帖子时在详细信息部分为其分配值,然后最终在组页脚中显示它,但我明白了相同的0.00结果。 I've tried both using a numeric global variable and do the conversion on the details-level, and using a string variable and do the conversion in the footer-level. 我尝试使用数字全局变量并在详细信息级别进行转换,并使用字符串变量并在页脚级别进行转换。

Solved it: 解决了:

if NumericText(Replace({#P-LDL}, ".", ",")) then
    ToNumber(Replace({#P-LDL}, ".", ","))

Stupid locales... 愚蠢的语言环境...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM