aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/frontend/html/util/friendly.js
blob: 6eee3a5b8a8f8c7955e90e3a74cd554b7102d896 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Copyright Epic Games, Inc. All Rights Reserved.

"use strict";

////////////////////////////////////////////////////////////////////////////////
export class Friendly
{
	static sep(value, prec=0)
	{
		return (+value).toLocaleString("en", {
			style: "decimal",
			minimumFractionDigits : prec,
			maximumFractionDigits : prec,
		});
	}

	static k(x)		{ return Friendly.sep((x + 999)  / Math.pow(10, 3), 0) + "K"; }
	static m(x)		{ return Friendly.sep( x         / Math.pow(10, 6), 1) + "M"; }
	static g(x)		{ return Friendly.sep( x         / Math.pow(10, 6), 2) + "G"; }
	static kib(x)	{ return Friendly.sep((x + 1023) / (1 << 10), 0) + " KiB"; }
	static mib(x)	{ return Friendly.sep( x         / (1 << 20), 1) + " MiB"; }
	static gib(x)	{ return Friendly.sep( x         / (1 << 30), 2) + " GiB"; }
}