Fix money rounding issue (#1094)

* Fix money rounding issue

* Re-add dollar signs

* Remove unncessary pre-rounding
This commit is contained in:
Prospector 2023-04-14 20:55:32 -07:00 committed by GitHub
parent 4398563b85
commit 257b35e4ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 14 deletions

View File

@ -42,9 +42,9 @@
<div class="grid-display__item">
<div class="label">Total revenue</div>
<div class="value">
{{ $formatMoney(payouts.all_time) }}
{{ $formatMoney(payouts.all_time, true) }}
</div>
<span>{{ $formatMoney(payouts.last_month) }} this month</span>
<span>{{ $formatMoney(payouts.last_month, true) }} this month</span>
<!-- <NuxtLink class="goto-link" to="/dashboard/analytics"-->
<!-- >View breakdown-->
<!-- <ChevronRightIcon-->
@ -55,7 +55,7 @@
<div class="grid-display__item">
<div class="label">Current balance</div>
<div class="value">
{{ $formatMoney(auth.user.payout_data.balance) }}
{{ $formatMoney(auth.user.payout_data.balance, true) }}
</div>
<NuxtLink
v-if="auth.user.payout_data.balance >= minWithdraw"
@ -93,9 +93,6 @@ const [raw] = await Promise.all([
])
const user = await useUser()
raw.all_time = Math.floor(raw.all_time * 100) / 100
raw.last_month = Math.floor(raw.last_month * 100) / 100
const payouts = ref(raw)
const minWithdraw = ref(0.26)

View File

@ -159,23 +159,24 @@ export default defineNuxtPlugin((nuxtApp) => {
})
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 (
'$' +