number format isn't localized #437

This commit is contained in:
Hillel Coren 2017-11-19 12:27:26 +02:00
parent a16de19ee7
commit 4de9b614dc
2 changed files with 17 additions and 2 deletions

View File

@ -459,6 +459,11 @@ class Utils
public static function parseFloat($value) public static function parseFloat($value)
{ {
// check for comma as decimal separator
if (preg_match('/,[\d]{1,2}$/', $value)) {
$value = str_replace(',', '.', $value);
}
$value = preg_replace('/[^0-9\.\-]/', '', $value); $value = preg_replace('/[^0-9\.\-]/', '', $value);
return floatval($value); return floatval($value);

View File

@ -27,8 +27,18 @@
@endif @endif
NINJA.parseFloat = function(str) { NINJA.parseFloat = function(str) {
if (!str) return ''; if (! str) {
str = (str+'').replace(/[^0-9\.\-]/g, ''); return '';
} else {
str = str + '';
}
// check for comma as decimal separator
if (str.match(/,[\d]{1,2}$/)) {
str = str.replace(',', '.');
}
str = str.replace(/[^0-9\.\-]/g, '');
return window.parseFloat(str); return window.parseFloat(str);
} }