As i was building a client site, i had a request like this: when he creates a node (Vehicle content type), among all the fields, he fills in a float value for the horsepower of the engine. He wanted the system to automatically convert that value in Kilowatts to and display it along the horsepower value and add a suffix " KW".
After creating the computed field, this are my settings:
Computed Code (PHP)
$entity_field[0]['value'] = $entity->field_mjet_kuajfuqi['und'][0]['value'] * 0.7456;
Where the field_mjet_kuajfuqi is the Horsepower field (i have named it in albanian) that i referenced to get the value, and multiplied it with the appropriate conversion value for 1 kilowatt.
Then on the Display Code (PHP) i did this:
$mycustomdisplay = number_format($entity_field_item['value'], 1, '.', '');
$display_output = $mycustomdisplay . " KW";
I applied the number_format php function to force the output to have only 1 value after the decimal point. And after that i concatenated it with the suffix String namely " KW".
In the database storage settings i used:
Data type: float
Data size: normal
Decimal Precision: 10
Decimal Scale: 1 // which did not work and made me use the number format in the display code above.