Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unformats a number formatted with number_format().
<?php
function number_unformat($number, $force_number = true, $dec_point = '.', $thousands_sep = ',') {
if ($force_number) {
$number = preg_replace('/^[^\d]+/', '', $number);
} else if (preg_match('/^[^\d]+/', $number)) {
return false;
}
$type = (strpos($number, $dec_point) === false) ? 'int' : 'float';
$number = str_replace(array($dec_point, $thousands_sep), array('.', ''), $number);
settype($number, $type);
return $number;
}
@jmramos02
Copy link

jmramos02 commented Apr 23, 2015

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment