Improve number formatting

closes #439
This commit is contained in:
Matthias 2021-07-30 20:34:12 +02:00
parent c6a866b96c
commit d0beeda943
2 changed files with 12 additions and 4 deletions

View File

@ -145,16 +145,18 @@ export default class TradeList extends Vue {
{ key: 'trade_id', label: 'ID' }, { key: 'trade_id', label: 'ID' },
{ key: 'pair', label: 'Pair' }, { key: 'pair', label: 'Pair' },
{ key: 'amount', label: 'Amount' }, { key: 'amount', label: 'Amount' },
{ key: 'stake_amount', label: 'Stake amount' }, {
key: 'stake_amount',
label: 'Stake amount',
formatter: (value: number) => this.formatPriceWithDecimals(value),
},
{ {
key: 'open_rate', key: 'open_rate',
label: 'Open rate', label: 'Open rate',
formatter: (value: number) => this.formatPriceWithDecimals(value),
}, },
{ {
key: this.activeTrades ? 'current_rate' : 'close_rate', key: this.activeTrades ? 'current_rate' : 'close_rate',
label: this.activeTrades ? 'Current rate' : 'Close rate', label: this.activeTrades ? 'Current rate' : 'Close rate',
formatter: (value: number) => this.formatPriceWithDecimals(value),
}, },
{ {
key: 'profit', key: 'profit',

View File

@ -10,8 +10,14 @@ export function formatPercent(value: number, decimals = 3): string {
return !isUndefined(value) ? `${(value * 100).toFixed(decimals)}%` : ''; return !isUndefined(value) ? `${(value * 100).toFixed(decimals)}%` : '';
} }
/**
* Format number to `decimals` without trailing zeros
* @param value Number to format
* @param decimals number of decimals (Defaults to 8)
* @returns Formatted string
*/
export function formatPrice(value: number, decimals = 8): string { export function formatPrice(value: number, decimals = 8): string {
return !isUndefined(value) ? value.toFixed(decimals) : ''; return !isUndefined(value) ? parseFloat(value.toFixed(decimals)).toString() : '';
} }
export function dateFromString(datestring: string, format: string): Date { export function dateFromString(datestring: string, format: string): Date {