Files
Iris/src/js/components/NiceNumber.js
James Barnsley e4d53a2d35 Auto eslint fix
2019-09-05 15:36:11 +12:00

24 lines
531 B
JavaScript
Executable File

import React, { memo } from 'react';
export default memo((props) => {
let formatted = parseInt(props.value);
// > 1 million
if (formatted > 1000000) {
formatted /= 1000000;
formatted = Math.round(formatted * 10) / 10;
formatted = `${formatted}m`;
// > 1 thousand
} else if (formatted > 1000) {
formatted /= 1000;
formatted = Math.round(formatted * 10) / 10;
formatted = `${formatted}k`;
} else {
formatted = formatted.toLocaleString();
}
return formatted;
});