fix(client/numpipe): handle Intl failure gently

pull/3643/head
kontrollanten 2021-01-27 09:16:04 +01:00
parent 1fe74db9c3
commit e275049f1f
1 changed files with 10 additions and 4 deletions

View File

@ -28,10 +28,16 @@ export class NumberFormatterPipe implements PipeTransform {
const calc = value / (format.max / 1000) const calc = value / (format.max / 1000)
const integralPart = Math.floor(calc) const integralPart = Math.floor(calc)
const decimalPart = NumberFormatterPipe.getDecimalForNumber(calc) const decimalPart = NumberFormatterPipe.getDecimalForNumber(calc)
const decimalSeparator = Intl.NumberFormat(this.localeId) let decimalSeparator
try {
decimalSeparator = Intl.NumberFormat(this.localeId)
.formatToParts(1.1) .formatToParts(1.1)
.find(part => part.type === 'decimal') .find(part => part.type === 'decimal')
.value .value
} catch (error) {
decimalSeparator = ','
}
return integralPart < 10 && decimalPart > 0 return integralPart < 10 && decimalPart > 0
? `${integralPart}${decimalSeparator}${decimalPart}${format.type}` ? `${integralPart}${decimalSeparator}${decimalPart}${format.type}`