Please be aware that whenever you cancel an upgrade, you will only be refunded half of the resource cost. Also, note that the refund will only be issued in the form of resources, never in gems, even if you used gems to start the upgrade. 

Once an upgrade has been cancelled, there is no way to undo the cancellation. Consider it carefully if you really want to cancel an ongoing upgrade  before following the instruction below:
1) Tap the building that you want to cancel the upgrade on
2) Tap on the Cancel button
3) A confirmation dialog will pop up. Confirm the cancellation by tapping on Yes.

The upgrade will be cancelled immediately.