Nowadays there is a native function [`to_dms()`](https://docs.qgis.org/3.16/en/docs/user_manual/working_with_vector/functions_list.html#to-dms) for this intent included in the expression calculator.

Now, you can simply run `to_dms(5.1234, 'x', 2)`. A capture of the current doc can be seen below

[![enter image description here][1]][1]

  [1]: https://i.sstatic.net/5ONEi.png