Create custom summary field

hi all
i am wondering how in a giving doctype create a summary field which summaries the last entries (decimal data) from one field and the new one already typed (row-1)+(row) like so.and save it to the database.

You can do it with Client Scripting or on Server Side events.
Please explain your use case.