diff options
Diffstat (limited to 'animism-align/frontend/app/utils')
| -rw-r--r-- | animism-align/frontend/app/utils/index.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/animism-align/frontend/app/utils/index.js b/animism-align/frontend/app/utils/index.js index dc80fee..92aa769 100644 --- a/animism-align/frontend/app/utils/index.js +++ b/animism-align/frontend/app/utils/index.js @@ -103,6 +103,26 @@ export const timestampToSeconds = time_str => { return time_str_parts[0] } +export const commatize = (n, radix) => { + radix = radix || -1 + var nums = [], i, counter = 0, r = Math.floor + if (radix !== -1 && n > radix) { + n /= radix + nums.unshift(r((n * 10) % 10)) + nums.unshift(".") + } + do { + i = r(n % 10) + n = r(n / 10) + counter += 1 + if (n && ! (counter % 3)) + { i = ',' + r(i) } + nums.unshift(i) + } + while (n) + return nums.join("") +} + export const percent = n => (n * 100).toFixed(1) + '%' export const px = (n, w) => Math.round(n * w) + 'px' |
