How to do simple subtraction in Computed Field? I'm trying to calculate the price difference between old price and new price, and if the price has dropped to display by how much, both Nominally and in Percent.

So, basically these are 2 simple formulas that should look like this:


  NOMINAL PRICE DROP = field_price_original - field_price_new  
  
  PERCENTAGE PRICE DROP =  ( (field_price_new - field_price_original) /
  field_price_original ) * 100


I tried setting this up through Rules (unsuccessfully), but it seems that doing it through Computed Field will not be so heavy on the server. 
Using Computing Field I have the following formula:


  $entity_field[0]['value'] =
  array_pop(array_pop(field_get_items($entity_type, $entity,
  'field_price_original'))) -
  array_pop(array_pop(field_get_items($entity_type, $entity,
  'field_price_new')));


The number is set as float, 10.2.   But for some reason it doesn't work.

Can someone please help and provide the correct syntax for Computed Field?
As per the documentation of computation field module to calculate the difference of two fields you need to use the PEAR:

$path = '/pathToPearsParentDirectory/pear/PEAR';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

require_once 'PEAR.php'; 
include_once "Text/Diff.php"; 
include_once "Text/Diff/Renderer.php"; 
include_once "Text/Diff/Renderer/inline.php";

$diff = &amp;new Text_Diff('auto', array(array($node-&gt;field_nameOfOneFieldToCompare[0]['value']), array($node-&gt;field_nameOfOtherFieldToCompare[0]['value']))); $renderer
= &amp;new Text_Diff_Renderer_inline();

$node_field[0]['value'] = $renderer-&gt;render($diff);


More info about it available here http://arencambre.com/blog/2009/05/17/how-i-got-field-diffs-working-with-drupal-pear-text_diff-and-dreamhost