From 257b35e4aef65bb80581bb137b5f32f1a70d0bf9 Mon Sep 17 00:00:00 2001
From: Prospector <6166773+Prospector@users.noreply.github.com>
Date: Fri, 14 Apr 2023 20:55:32 -0700
Subject: [PATCH] Fix money rounding issue (#1094)
* Fix money rounding issue
* Re-add dollar signs
* Remove unncessary pre-rounding
---
pages/dashboard/index.vue | 9 +++------
plugins/shorthands.js | 17 +++++++++--------
2 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/pages/dashboard/index.vue b/pages/dashboard/index.vue
index abd4ef71c..9a3472b39 100644
--- a/pages/dashboard/index.vue
+++ b/pages/dashboard/index.vue
@@ -42,9 +42,9 @@
Total revenue
- {{ $formatMoney(payouts.all_time) }}
+ {{ $formatMoney(payouts.all_time, true) }}
-
{{ $formatMoney(payouts.last_month) }} this month
+
{{ $formatMoney(payouts.last_month, true) }} this month
@@ -55,7 +55,7 @@
Current balance
- {{ $formatMoney(auth.user.payout_data.balance) }}
+ {{ $formatMoney(auth.user.payout_data.balance, true) }}
{
})
nuxtApp.provide('sortedCategories', sortedCategories)
})
-export const formatNumber = (number) => {
+export const formatNumber = (number, abbreviate = true) => {
const x = +number
- if (x >= 1000000) {
+ if (x >= 1000000 && abbreviate) {
return (x / 1000000).toFixed(2).toString() + 'M'
- } else if (x >= 10000) {
- return (x / 1000).toFixed(1).toString() + 'K'
+ } else if (x >= 10000 && abbreviate) {
+ return (x / 1000).toFixed(1).toString() + 'k'
} else {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}
}
-export const formatMoney = (number) => {
+export const formatMoney = (number, abbreviate = false) => {
+ number = Math.floor(number * 100) / 100
const x = +number
- if (x >= 1000000) {
+ if (x >= 1000000 && abbreviate) {
return '$' + (x / 1000000).toFixed(2).toString() + 'M'
- } else if (x >= 10000) {
- return '$' + (x / 1000).toFixed(1).toString() + 'K'
+ } else if (x >= 10000 && abbreviate) {
+ return '$' + (x / 1000).toFixed(2).toString() + 'k'
} else {
return (
'$' +