Give metric approximation.

This commit is contained in:
Thaddee Tyl 2014-01-06 16:48:28 +01:00
parent 0fb6073017
commit 0e5e5e4f90
2 changed files with 15 additions and 4 deletions

View File

@ -67,7 +67,7 @@ function(data, match, end, ask) {
badge(badgeData, makeSend(format, ask.res, end));
return;
}
badgeData.text[1] = '$' + money + ' /week';
badgeData.text[1] = '$' + metric(money) + ' /week';
if (money === 0) {
badgeData.colorscheme = 'red';
} else if (money < 10) {
@ -105,7 +105,7 @@ function(data, match, end, ask) {
badge(badgeData, makeSend(format, ask.res, end));
return;
}
badgeData.text[1] = monthly + ' /month';
badgeData.text[1] = metric(monthly) + ' /month';
if (monthly === 0) {
badgeData.colorscheme = 'red';
} else if (monthly < 10) {
@ -155,7 +155,7 @@ function(data, match, end, ask) {
badge(badgeData, makeSend(format, ask.res, end));
return;
}
badgeData.text[1] = monthly + ' /month';
badgeData.text[1] = metric(monthly) + ' /month';
if (monthly === 0) {
badgeData.colorscheme = 'red';
} else if (monthly < 10) {
@ -356,3 +356,14 @@ function streamFromString(str) {
newStream._read = function() { newStream.push(str); newStream.push(null); };
return newStream;
}
// Given a number, string with appropriate unit in the metric system, SI.
function metric(n) {
var limit = 1000;
if (n > limit) {
n = Math.round(n / 1000);
return ''+n + 'k';
} else {
return ''+n;
}
}

View File

@ -62,7 +62,7 @@ I wanted a service for everyone. <br/>
I made the GitHub Badge Service.
</p>
<img src='/:download-.5K-blue.svg' alt='Download: .5K'/>
<img src='/:download-.8 kB-blue.svg' alt='Download: .5kB'/>
<p>
Here's how it works. <br/>