2019-02-21 16:56:07 +13:00
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
import React, { memo } from 'react';
|
2019-02-21 16:56:07 +13:00
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
export default memo((props) => {
|
|
|
|
|
let formatted = parseInt(props.value);
|
2019-02-21 16:56:07 +13:00
|
|
|
|
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-02-21 16:56:07 +13:00
|
|
|
|
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-02-21 16:56:07 +13:00
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
return formatted;
|
|
|
|
|
});
|