User Muhammad Nabeel Arif in the StackOverflow forum provided a good working code to convert DP to Pixel and vice versa.

It is up to you if you want to keep the value returned as a float. I wanted to have it returned as an int, hence the cast.