diff --git a/common/util/format.ts b/common/util/format.ts index c8d363d3..d7e381b4 100644 --- a/common/util/format.ts +++ b/common/util/format.ts @@ -19,7 +19,9 @@ export function formatWithCommas(amount: number) { } export function formatPercent(zeroToOne: number) { - return Math.round(zeroToOne * 100) + '%' + // Show 1 decimal place if <2% or >99% + const decimalPlaces = zeroToOne < 0.02 || zeroToOne > 0.99 ? 1 : 0 + return (zeroToOne * 100).toFixed(decimalPlaces) + '%' } export function toCamelCase(words: string) { diff --git a/web/lib/firebase/contracts.ts b/web/lib/firebase/contracts.ts index 24133c65..5436a25b 100644 --- a/web/lib/firebase/contracts.ts +++ b/web/lib/firebase/contracts.ts @@ -21,7 +21,7 @@ import { Binary, Contract, FullContract } from '../../../common/contract' import { getDpmProbability } from '../../../common/calculate-dpm' import { createRNG, shuffle } from '../../../common/util/random' import { getCpmmProbability } from '../../../common/calculate-cpmm' -import { formatMoney } from '../../../common/util/format' +import { formatMoney, formatPercent } from '../../../common/util/format' import { getCpmmLiquidity } from '../../../common/calculate-cpmm' export type { Contract } @@ -58,8 +58,7 @@ export function getBinaryProbPercent(contract: FullContract) { ? getCpmmProbability(pool, p) : getDpmProbability(totalShares) - const probPercent = Math.round(prob * 100) + '%' - return probPercent + return formatPercent(prob) } export function tradingAllowed(contract: Contract) {