2017-07-13 21:02:39 +00:00
|
|
|
// @flow
|
|
|
|
import Big from 'big.js';
|
2017-06-24 18:17:09 +00:00
|
|
|
|
|
|
|
export function toFixedIfLarger(number: number, fixedSize: number = 6): string {
|
2017-06-24 19:53:53 +00:00
|
|
|
return parseFloat(number.toFixed(fixedSize)).toString();
|
2017-06-24 18:17:09 +00:00
|
|
|
}
|
2017-07-13 21:02:39 +00:00
|
|
|
|
|
|
|
// Use in place of angular number filter
|
|
|
|
export function formatNumber(number: Big, digits: number = 3): string {
|
|
|
|
let parts = number.toFixed(digits).split('.');
|
|
|
|
parts[1] = parts[1].replace(/0+/, '');
|
|
|
|
if (!parts[1]) {
|
|
|
|
parts.pop();
|
|
|
|
}
|
|
|
|
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
|
|
|
|
|
|
return parts.join('.');
|
|
|
|
}
|