Files
Iris/src/js/components/NiceNumber.js

24 lines
531 B
JavaScript
Raw Normal View History

2019-09-05 15:36:11 +12:00
import React, { memo } from 'react';
2019-09-05 15:36:11 +12:00
export default memo((props) => {
let formatted = parseInt(props.value);
2019-09-05 15:36:11 +12:00
// > 1 million
if (formatted > 1000000) {
formatted /= 1000000;
formatted = Math.round(formatted * 10) / 10;
formatted = `${formatted}m`;
2019-09-05 15:36:11 +12:00
// > 1 thousand
} else if (formatted > 1000) {
formatted /= 1000;
formatted = Math.round(formatted * 10) / 10;
formatted = `${formatted}k`;
} else {
formatted = formatted.toLocaleString();
}
2019-09-05 15:36:11 +12:00
return formatted;
});