Add a + sign to a +ve number in PHP
- by user318466
I need to design a function to return -ve numbers unchanged but should add a + sign at the start of the number if its alreay no present.
Example:
Input Output
----------------
+1 +1
1 +1
-1 -1
It will get only numeric input.
function formatNum($num)
{
# something here..perhaps a regex?
}
This function is going to be called several times in echo/print so the quicker the better.