gui: Localize number formatting (fixes #4896) (#4902)

This commit is contained in:
Wulf Weich
2018-04-25 10:26:49 +02:00
committed by Jakob Borg
parent 78094fa0cb
commit 2c18640386
6 changed files with 30 additions and 39 deletions

View File

@@ -6,16 +6,16 @@ angular.module('syncthing.core')
}
if (input > 1024 * 1024 * 1024) {
input /= 1024 * 1024 * 1024;
return input.toFixed(decimals(input, 2)) + ' Gi';
return input.toLocaleString(undefined, {maximumFractionDigits: 2}) + ' Gi';
}
if (input > 1024 * 1024) {
input /= 1024 * 1024;
return input.toFixed(decimals(input, 2)) + ' Mi';
return input.toLocaleString(undefined, {maximumFractionDigits: 2}) + ' Mi';
}
if (input > 1024) {
input /= 1024;
return input.toFixed(decimals(input, 2)) + ' Ki';
return input.toLocaleString(undefined, {maximumFractionDigits: 2}) + ' Ki';
}
return Math.round(input) + ' ';
return Math.round(input).toLocaleString(undefined, {maximumFractionDigits: 2}) + ' ';
};
});

View File

@@ -0,0 +1,9 @@
angular.module('syncthing.core')
.filter('localeNumber', function () {
return function (input, decimals) {
if (typeof(decimals) !== 'undefined') {
return input.toLocaleString(undefined, {maximumFractionDigits: decimals});
}
return input.toLocaleString();
};
});

View File

@@ -6,16 +6,16 @@ angular.module('syncthing.core')
}
if (input > 1000 * 1000 * 1000) {
input /= 1000 * 1000 * 1000;
return input.toFixed(decimals(input, 2)) + ' G';
return input.toLocaleString(undefined, {maximumFractionDigits: 2}) + ' G';
}
if (input > 1000 * 1000) {
input /= 1000 * 1000;
return input.toFixed(decimals(input, 2)) + ' M';
return input.toLocaleString(undefined, {maximumFractionDigits: 2}) + ' M';
}
if (input > 1000) {
input /= 1000;
return input.toFixed(decimals(input, 2)) + ' k';
return input.toLocaleString(undefined, {maximumFractionDigits: 2}) + ' k';
}
return Math.round(input) + ' ';
return Math.round(input).toLocaleString(undefined, {maximumFractionDigits: 2}) + ' ';
};
});

View File

@@ -1,6 +0,0 @@
angular.module('syncthing.core')
.filter('natural', function () {
return function (input, valid) {
return input.toFixed(decimals(input, valid));
};
});