Display one decimal for metrics smaller than 10 (#3735)
* Display one decimal for metrics smaller than 10 * Update test validators * Run Prettier * Update GitHub regexes
This commit is contained in:
@@ -56,9 +56,17 @@ function metric(n) {
|
||||
for (let i = metricPrefix.length - 1; i >= 0; i--) {
|
||||
const limit = metricPower[i]
|
||||
if (n >= limit) {
|
||||
n = Math.round(n / limit)
|
||||
if (n < 1000) {
|
||||
return `${n}${metricPrefix[i]}`
|
||||
const scaledN = n / limit
|
||||
if (scaledN < 10) {
|
||||
// For "small" numbers, display one decimal digit unless it is 0.
|
||||
const oneDecimalN = scaledN.toFixed(1)
|
||||
if (oneDecimalN.charAt(oneDecimalN.length - 1) !== '0') {
|
||||
return `${oneDecimalN}${metricPrefix[i]}`
|
||||
}
|
||||
}
|
||||
const roundedN = Math.round(scaledN)
|
||||
if (roundedN < 1000) {
|
||||
return `${roundedN}${metricPrefix[i]}`
|
||||
} else {
|
||||
return `1${metricPrefix[i + 1]}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user