Calculate percentage between two entity fields in Drupal using Computed Field Module I am trying to calculate a % of two entity fields in Drupal 7 using Computed Field module.

$entity_field[0]['value'] = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_accounts_payable_bs'))) /
$entity_field[0]['value'] = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_customer_deposits_bs')));


Display:

$display_output = number_format($entity_field_item['value'] , 1 , '.' , ',');


Current the value I get is ".20" But I want it "20.0"
First print_r($data) in your Output code text area so you can see what you can work with. Depending on what you have, your Output code is going to look something like this:

$percent = 100 * $data-&gt;field_accounts_payable_bs['0']['raw']['value'] / $data-&gt;field_customer_deposits_bs['0']['raw']['value'];

print(number_format($percent, 1, '.', ','));