Merge pull request #92 from lbryio/format-credits-tweak

use parseFloat for the amount argument
This commit is contained in:
Akinwale Ariwodola 2018-10-28 22:45:28 +01:00 committed by GitHub
commit 5ddcb60d31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

3
dist/bundle.js vendored
View file

@ -5100,7 +5100,8 @@ exports.formatCredits = formatCredits;
exports.formatFullPrice = formatFullPrice;
exports.creditsToString = creditsToString;
function formatCredits(amount, precision) {
return amount.toFixed(precision || 1).replace(/\.?0+$/, '');
if (Number.isNaN(parseFloat(amount))) return '0';
return parseFloat(amount).toFixed(precision || 1).replace(/\.?0+$/, '');
}
function formatFullPrice(amount) {

View file

@ -1,5 +1,8 @@
export function formatCredits(amount, precision) {
return amount.toFixed(precision || 1).replace(/\.?0+$/, '');
if (Number.isNaN(parseFloat(amount))) return '0';
return parseFloat(amount)
.toFixed(precision || 1)
.replace(/\.?0+$/, '');
}
export function formatFullPrice(amount, precision = 1) {
@ -10,7 +13,7 @@ export function formatFullPrice(amount, precision = 1) {
if (fraction) {
const decimals = fraction.split('');
const first = decimals.filter(number => number !== '0')[0];
const first = decimals.filter((number) => number !== '0')[0];
const index = decimals.indexOf(first);
// Set format fraction