• Tyler T.

    (@awebco)


    How can we get the percentage of field_A & field_B and then display that percent in field_C?

    Example
    field_A = 100
    field_B = 30
    field_C = 30%

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor nick6352683

    (@nick6352683)

    Hi Tyler,

    First of all you cannot start your field names with “field_”, ACF will warn you if you try that. So for this example, I simply renamed your field names to a,b, and c (make sure they are all numeric fields).

    So if a=100 and b=30, then the formula to use in c is (b / a) * 100

    And the answer in this case in field c will be 30.

    You can make field c to be Read Only, and you can Append the field with the percentage sign (%). You have to also do that on the front end if you want the % sign to show up…

    Good luck.

    Thread Starter Tyler T.

    (@awebco)

    Nick,

    Thanks a ton! I believe this worked.

    Do you know how I set field A & B to automatically add commas for things like 10,000?

    Plugin Contributor nick6352683

    (@nick6352683)

    Sorry for the delay Tyler, I just saw your question:

    Let’s say you have a repeater field where you have a calculated sub field (cost), and in the case I want to have a dollar sign in front of the number, and thousands separator.

    So I get the value of the subfield (cost) and store it in a variable – in this example $linecost, and then echo that variable, and format it for 2 decimal points. Instead of the 2, if you put 0, then you won’t have decimal points, but you will still get the coma (,) as the thousands separator.

    $<?php $linecost = get_sub_field(‘cost’);
    echo number_format($linecost,2); ?>

    I hope that helps.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Percentage Calculation?’ is closed to new replies.