how to calculate a value by rules
The Math Field module defines a new field type to dynamically calculate values on entity forms. This is an alternative to Computed Field
that does not require the use of PHP Filter.

Note: the above info is an excerpt from its project page.