mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-24 17:14:04 +02:00
Preserve precision in raw tags
This commit is contained in:
@@ -448,7 +448,7 @@ export function coreLocalizer() {
|
||||
*/
|
||||
localizer.floatParser = (locale) => {
|
||||
// https://stackoverflow.com/a/55366435/4585461
|
||||
const polyfill = (string) => parseFloat(string.trim());
|
||||
const polyfill = (string) => +string.trim();
|
||||
if (!('Intl' in window && 'NumberFormat' in Intl)) return polyfill;
|
||||
const format = new Intl.NumberFormat(locale, { maximumFractionDigits: 20 });
|
||||
if (!('formatToParts' in format)) return polyfill;
|
||||
@@ -481,7 +481,7 @@ export function coreLocalizer() {
|
||||
var literal, group, decimal;
|
||||
if ('Intl' in window && 'NumberFormat' in Intl) {
|
||||
const format = new Intl.NumberFormat(locale, { maximumFractionDigits: 20 });
|
||||
if (('formatToParts' in format)) {
|
||||
if ('formatToParts' in format) {
|
||||
const parts = format.formatToParts(-12345.6);
|
||||
const literalPart = parts.find(d => d.type === 'literal');
|
||||
literal = literalPart && new RegExp(`[${literalPart.value}]`, 'g');
|
||||
|
||||
@@ -401,7 +401,8 @@ export function uiFieldText(field, context) {
|
||||
var vals = val.split(';');
|
||||
vals = vals.map(function(v) {
|
||||
var num = parseLocaleFloat(v);
|
||||
return isFinite(num) ? clamped(num) : v;
|
||||
const fractionDigits = countDecimalPlaces(v);
|
||||
return isFinite(num) ? clamped(num).toFixed(fractionDigits) : v;
|
||||
});
|
||||
val = vals.join(';');
|
||||
}
|
||||
@@ -429,9 +430,10 @@ export function uiFieldText(field, context) {
|
||||
var vals = val.split(';');
|
||||
vals = vals.map(function(v) {
|
||||
v = v.trim();
|
||||
var num = parseFloat(v);
|
||||
var num = Number(v);
|
||||
if (!isFinite(num)) return v;
|
||||
return formatFloat(clamped(num));
|
||||
const fractionDigits = v.includes('.') ? v.split('.')[1].length : 0;
|
||||
return formatFloat(clamped(num), fractionDigits);
|
||||
});
|
||||
val = vals.join(';');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user