I am trying to convert a 4 digit integer like 1999
to 19.99
.
I have looked at functions like money_format()
but this seems to not be what I am looking for. Here is a function I wrote but there must be pre-existing method to do this?
function numberToDecimal((int)$num) {
if(!preg_match('/^\d{4}$/', $num) return;
$parsed = (string)$num;
$i = 0;
$ret = $parsed[$i++] . $parsed[$i++] . '.';
$ret .= $parsed[$i++] . $parsed[$i];
return $ret;
}
Thank-you in advance.
See the code working over at corresponding to the answer 3v4l.