Search code examples
crystal-reportstype-conversioncrystal-reports-xicumulative-sum

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

  • 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. 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.

Solution

  • Solved it:

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

    Stupid locales...