Show 1 decimal point on probability tails

This commit is contained in:
Austin Chen 2022-03-18 19:12:44 -07:00
parent 224a8214b4
commit 7d5d945a20
2 changed files with 5 additions and 4 deletions

View File

@ -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) {

View File

@ -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<any, Binary>) {
? getCpmmProbability(pool, p)
: getDpmProbability(totalShares)
const probPercent = Math.round(prob * 100) + '%'
return probPercent
return formatPercent(prob)
}
export function tradingAllowed(contract: Contract) {