Show decimals on 98%+

This commit is contained in:
Austin Chen 2022-03-18 20:02:04 -07:00
parent 434c7b6b97
commit d6a751d9a2
3 changed files with 4 additions and 4 deletions

View File

@ -19,8 +19,8 @@ export function formatWithCommas(amount: number) {
}
export function formatPercent(zeroToOne: number) {
// Show 1 decimal place if <2% or >99%
const decimalPlaces = zeroToOne < 0.02 || zeroToOne > 0.99 ? 1 : 0
// Show 1 decimal place if <2% or >98%, giving more resolution on the tails
const decimalPlaces = zeroToOne < 0.02 || zeroToOne > 0.98 ? 1 : 0
return (zeroToOne * 100).toFixed(decimalPlaces) + '%'
}

View File

@ -95,7 +95,7 @@ export function AnswerBetPanel(props: {
: 0
const currentReturn = betAmount ? (currentPayout - betAmount) / betAmount : 0
const currentReturnPercent = (currentReturn * 100).toFixed() + '%'
const currentReturnPercent = formatPercent(currentReturn)
return (
<Col className={clsx('px-2 pb-2 pt-4 sm:pt-0', className)}>

View File

@ -112,7 +112,7 @@ export function BetPanel(props: {
: 0
const currentReturn = betAmount ? (currentPayout - betAmount) / betAmount : 0
const currentReturnPercent = (currentReturn * 100).toFixed() + '%'
const currentReturnPercent = formatPercent(currentReturn)
const panelTitle = title ?? 'Place a trade'
if (title) {