• I have been using the The Template Helper Class for a few years and have written a custom template that adds many records. I have been using the get_value, adding together and then outputting the result using echo (money_format’%i’, $AddedValues)

    After the last update, the print_field is putting a comma in the values eg. 117,466.00 (which I can’t remember if it always output this format, BUT,
    the added totals are only adding the numbers before the comma.
    eg:

    get_value(117,466.00) + get_value(0.00) = $AddedValues
    echo(money_format(‘%i’, $AddedValues) = 117.00

    I can sort out the problem by adding a str_replace(‘,’, ”, $value) to every single value that I am using in my calculations, but this is a massive undertaking.

    Do you know what has caused this change in behavior of data type, so that get_value is no longer recognizing the string as a numeric and was it intentional?

    Is there any easy solution, or do I need to rectify all my code for strictness.

    Thank you

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author xnau webdesign

    (@xnau)

    There was a change to how numbers are displayed so they are now localized, and that can add commas to the value.

    However, this does not affect the get_value method of the PDb_Template class…that will continue to be a number that can be used in numeric calculations. I just tested this.

    What I see in your code is not how the get_value method is normally used: the get_value method is expecting the name of the field (so it can get that particular value) and not a literal number. For example, if the field is named “payment”:

    <?php $record->get_value('payment') ?>

    If I could see the actual code you are using, I could comment more specifically.

    Thread Starter Karen Turner

    (@karen-turner)

    Here is an example of the code:

    <p class = “text-third”>
    <?php $msol_client->print_field(‘basic_annual_earned_income_app1’) ?>
    </p>

    <p class = “text-third”>
    <?php $msol_client->print_field(‘basic_annual_earned_income_app_2’) ?>
    </p>

    <p class = “text-third-total”>
    <?php echo(money_format(‘%i’,$msol_client->get_value(‘basic_annual_earned_income_app1’) + $msol_client->get_value(‘basic_annual_earned_income_app_2’) ) ); ?>
    </p>

    The output from this code is

    117,466.00 0.00 117.00

    Plugin Author xnau webdesign

    (@xnau)

    OK, what kind of field is basic_annual_earned_income_app1 ?

    Thread Starter Karen Turner

    (@karen-turner)

    basic_annual_earned_income_app1 is a currency field

    I have tried rolling back the plugin to check that it is the update that has caused the problem. I see that the currency field did not have a comma previously and the calculations all worked.

    Thanks

    Plugin Author xnau webdesign

    (@xnau)

    Yes, the comma was added recently, but that is for display only, the actual value in the field remains numeric with no commas. I honestly don’t understand how it’s getting into your value. It doesn’t do that in my tests.

    What do you get if you are using the money_format function to format the results?

    Thread Starter Karen Turner

    (@karen-turner)

    In the code line
    <?php echo(money_format(‘%i’,$msol_client->get_value(‘basic_annual_earned_income_app1’) + $msol_client->get_value(‘basic_annual_earned_income_app_2’) ) );
    ?>

    the result is output as 117.00

    where basic_annual_earned_income_app1 = 117466.00
    basic_annual_earned_income_app_2 = 0.0

    If I remove the money_format

    <?php
    echo($msol_client->get_value(‘basic_annual_earned_income_app1’) + $msol_client->get_value(‘basic_annual_earned_income_app_2’) );
    ?>
    the result is output exactly the same 117.00

    If I rollback to version 1.9.3.8
    the result without money_format is 117466
    with money_format is 117466.00

    I am using Participants Database HTML5 Form Elements and Participants Database Datepicker not that that should effect anything, but just in case.

    Thread Starter Karen Turner

    (@karen-turner)

    If I remove the comma from the field ie
    <?php
    echo(money_format(‘%i’,(str_replace(‘,’,”,$msol_client->get_value(‘basic_annual_earned_income_app1’)) + (str_replace(‘,’,”,$msol_client->get_value(‘basic_annual_earned_income_app_2’)) ) )));
    ?>

    Then I get the correct output 117466.00

    Plugin Author xnau webdesign

    (@xnau)

    OK, thanks for the detail, I need to take a closer look at this, see if I can duplicate your result so I can solve the issue.

    Plugin Author xnau webdesign

    (@xnau)

    Check for an update to Participants Database that addresses this issue.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Template Helper class get_value no longer recognising a number string’ is closed to new replies.