Support

Account

Home Forums General Issues A simple calculation, right?

Solved

A simple calculation, right?

  • Good morning,

    I have been using ACF for a long time and always found it to do exactly what is required, however I am stuck lol 🙂

    I have simple PHP calculation that I need to build into my templates but am rubbish at PHP (I have tried and read online before running for help).

    I have a field ‘7_day_rate’ and I need to divide this field by 7, simple right?

    Here is what I have been trying..

    <?php
    echo (“the_field(‘7_day_rate’)” / 7);
    ?>

    When I run this code, I always get a value of zero (0) even though I am sure that the field ‘7_day_rate’ has a value above zero.

    Can anyone point me in the right direction?

  • You’ve got a couple of things going on here, but I think it should be

    echo (get_field('7_day_rate')/7);

  • Thank you very, very much John!

    Just incase anyone else stumbles upon this looking for something similar, I ended up using this code to keep it to two decimal points.

    <?php
    $number = (get_field('7_day_rate')/7);
    echo number_format($number, 2). "";
    ?>
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.