aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/shared-main/angular/number-formatter.pipe.ts19
1 files changed, 17 insertions, 2 deletions
diff --git a/client/src/app/shared/shared-main/angular/number-formatter.pipe.ts b/client/src/app/shared/shared-main/angular/number-formatter.pipe.ts
index e2eba3a60..5e6ccfa16 100644
--- a/client/src/app/shared/shared-main/angular/number-formatter.pipe.ts
+++ b/client/src/app/shared/shared-main/angular/number-formatter.pipe.ts
@@ -10,10 +10,25 @@ export class NumberFormatterPipe implements PipeTransform {
10 { max: 1000000000, type: 'M' } 10 { max: 1000000000, type: 'M' }
11 ] 11 ]
12 12
13 /**
14 * @param x number
15 * @param n number of decimals to get (defaults to 1, needs to be >= 1)
16 */
17 static getDecimalForNumber (x: number, n = 1) {
18 const v = x.toString().split('.')
19 const f = v[1] || ''
20 if (f.length > n) return +f.substr(0, n)
21 return +f
22 }
23
13 transform (value: number) { 24 transform (value: number) {
14 const format = this.dictionary.find(d => value < d.max) || this.dictionary[this.dictionary.length - 1] 25 const format = this.dictionary.find(d => value < d.max) || this.dictionary[this.dictionary.length - 1]
15 const calc = Math.floor(value / (format.max / 1000)) 26 const calc = value / (format.max / 1000)
27 const integralPart = Math.floor(calc)
28 const decimalPart = NumberFormatterPipe.getDecimalForNumber(calc)
16 29
17 return `${calc}${format.type}` 30 return integralPart < 10 && decimalPart > 0
31 ? `${integralPart}.${decimalPart}${format.type}`
32 : `${integralPart}${format.type}`
18 } 33 }
19} 34}