lbry-redux/src/util/formatCredits.js
2018-04-05 03:57:29 +01:00

21 lines
587 B
JavaScript

export function formatCredits(amount, precision) {
return amount.toFixed(precision || 1).replace(/\.?0+$/, '');
}
export function formatFullPrice(amount, precision = 1) {
let formated = '';
const quantity = amount.toString().split('.');
const fraction = quantity[1];
if (fraction) {
const decimals = fraction.split('');
const first = decimals.filter(number => number !== '0')[0];
const index = decimals.indexOf(first);
// Set format fraction
formated = `.${fraction.substring(0, index + precision)}`;
}
return parseFloat(quantity[0] + formated);
}