diff --git a/src/utils/usePrice.ts b/src/utils/usePrice.ts index ca689d8..27ef5bc 100644 --- a/src/utils/usePrice.ts +++ b/src/utils/usePrice.ts @@ -24,6 +24,14 @@ export function useTowDecimal(num: string | number): string | number { return formatGroupedPrice(Math.round(+num * 100) / 100, false) } +export function formatSignedPercentChange(value: number): string { + if (!value) return '0%' + + const formatted = useTowDecimal(Math.abs(value)) + const prefix = value > 0 ? '+' : '-' + return `${prefix}${formatted}%` +} + export function useFormat(num: string | number, unit = '') { return usePrice(Math.abs(+useTowDecimal(num)), true, unit) } diff --git a/src/views/base/home/components/CurrentPrice.vue b/src/views/base/home/components/CurrentPrice.vue index 3ff433c..1c6d5f1 100644 --- a/src/views/base/home/components/CurrentPrice.vue +++ b/src/views/base/home/components/CurrentPrice.vue @@ -4,23 +4,22 @@
-
{{ useTowDecimal(percentPriceChanged()) }}%
-
- -
+ + {{ formatSignedPercentChange(percentChange) }}
ریال
@@ -29,33 +28,55 @@ -// انیمیشن fade-in - \ No newline at end of file + diff --git a/src/views/base/home/desktop/components/DesktopLivePrice.vue b/src/views/base/home/desktop/components/DesktopLivePrice.vue index 09939f0..d867612 100644 --- a/src/views/base/home/desktop/components/DesktopLivePrice.vue +++ b/src/views/base/home/desktop/components/DesktopLivePrice.vue @@ -6,9 +6,13 @@ - {{ useTowDecimal(percentChange) }}% + + {{ formatSignedPercentChange(percentChange) }}