Skip to content

Instantly share code, notes, and snippets.

@msng
Created December 21, 2011 02:07
Show Gist options
  • Save msng/1504235 to your computer and use it in GitHub Desktop.
Save msng/1504235 to your computer and use it in GitHub Desktop.
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;
}
@donjose24
Copy link

Thanks!

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