Use of Decimals to Display user setting to format numbers (#1695)
Co-authored-by: Jose Alberto Hernandez <alberto@MacBook-Pro.local>
This commit is contained in:
co-authored by
Jose Alberto Hernandez
parent
814bb87c16
commit
99c2d4780d
@@ -0,0 +1,24 @@
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
|
||||
@Pipe({
|
||||
name: 'formatNumber'
|
||||
})
|
||||
export class FormatNumberPipe implements PipeTransform {
|
||||
|
||||
constructor(private decimalFormat: DecimalPipe,
|
||||
private settingsService: SettingsService) {
|
||||
}
|
||||
|
||||
transform(value: string | number, ...args: unknown[]): string {
|
||||
if (!value) {
|
||||
return '';
|
||||
}
|
||||
const locale = this.settingsService.language.code;
|
||||
const decimals = this.settingsService.decimals;
|
||||
const format = `1.${decimals}-${decimals}`;
|
||||
return this.decimalFormat.transform(value, format, locale);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user