21 lines
587 B
JavaScript
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);
|
|
}
|