From d6a751d9a2cf1a19a64d3b02fd584c50b964d78f Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Fri, 18 Mar 2022 20:02:04 -0700 Subject: [PATCH] Show decimals on 98%+ --- common/util/format.ts | 4 ++-- web/components/answers/answer-bet-panel.tsx | 2 +- web/components/bet-panel.tsx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/util/format.ts b/common/util/format.ts index d7e381b4..05a8f702 100644 --- a/common/util/format.ts +++ b/common/util/format.ts @@ -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) + '%' } diff --git a/web/components/answers/answer-bet-panel.tsx b/web/components/answers/answer-bet-panel.tsx index fa508937..65758f0b 100644 --- a/web/components/answers/answer-bet-panel.tsx +++ b/web/components/answers/answer-bet-panel.tsx @@ -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 ( diff --git a/web/components/bet-panel.tsx b/web/components/bet-panel.tsx index 21c15a50..16fb2a4f 100644 --- a/web/components/bet-panel.tsx +++ b/web/components/bet-panel.tsx @@ -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) {