Unit price with discount

Unit price with discount

Could someone help me to crate a custom function for getting the unit price with discount please? 

I've already created a custom field (in items) where i want to put the unit price with the discount in it. So what i need is a custom function that could make this operation for each item in the estimate: 

rate * (1- %discount) --- if the discount is in %
or
rate - discount --- if the discount is in $

Thank you in advance