mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-21 23:53:52 +00:00
Add formatPriceCurrency
This commit is contained in:
parent
ac948fccee
commit
d7ed2e46c8
|
@ -20,6 +20,17 @@ export function formatPrice(value: number, decimals = 8): string {
|
|||
return !isUndefined(value) ? parseFloat(value.toFixed(decimals)).toString() : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats price in the format "<price> <StakeCurrency>" using "deciaml" decimals
|
||||
* @param price Price to format
|
||||
* @param currency currency to use
|
||||
* @param decimals Decimals
|
||||
* @returns
|
||||
*/
|
||||
export function formatPriceCurrency(price, currency: string, decimals = 3) {
|
||||
return `${formatPrice(price, decimals)} ${currency}`;
|
||||
}
|
||||
|
||||
export function dateFromString(datestring: string, format: string): Date {
|
||||
return parse(datestring, format, 0);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
import { formatPercent } from '@/shared/formatters';
|
||||
import { formatPercent, formatPriceCurrency } from '@/shared/formatters';
|
||||
|
||||
describe('formatters.ts', () => {
|
||||
it('Format percent correctly', () => {
|
||||
expect(formatPercent(0.5)).toEqual('50.000%');
|
||||
});
|
||||
|
||||
it('format price currency as expected', () => {
|
||||
expect(formatPriceCurrency(5123.551123, 'USDT', 3)).toEqual('5123.551 USDT');
|
||||
expect(formatPriceCurrency(5123.551123, 'USDT')).toEqual('5123.551 USDT');
|
||||
expect(formatPriceCurrency(5123.551123, 'USDT', 5)).toEqual('5123.55112 USDT');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user