diff --git a/src/Faction/ui/DonateOption.tsx b/src/Faction/ui/DonateOption.tsx index c7bed8247..b1b1c21fe 100644 --- a/src/Faction/ui/DonateOption.tsx +++ b/src/Faction/ui/DonateOption.tsx @@ -12,6 +12,8 @@ import { Reputation } from "../../ui/React/Reputation"; import { StdButton } from "../../ui/React/StdButton"; +import { numeralWrapper } from "../../ui/numeralFormat"; + import { dialogBoxCreate } from "../../../utils/DialogBox"; type IProps = { @@ -73,7 +75,7 @@ export class DonateOption extends React.Component { } handleChange(e: React.ChangeEvent): void { - const amt = parseFloat(e.target.value); + const amt = numeralWrapper.parse(e.target.value); if (isNaN(amt)) { this.setState({ diff --git a/src/ui/numeralFormat.ts b/src/ui/numeralFormat.ts index 86e32f61c..0e2c372e6 100644 --- a/src/ui/numeralFormat.ts +++ b/src/ui/numeralFormat.ts @@ -138,6 +138,22 @@ class NumeralFormatter { formatThreads(n: number): string { return this.format(n, "0,0"); } + + parse(s: string): number { + // numeral library does not handle formats like 1e10 well (returns 110), + // so if both return a valid number, return the biggest one + const numeralValue = numeral(s).value(); + const parsed = parseFloat(s); + if (isNaN(parsed) && numeralValue === null) { + return NaN; + } else if (isNaN(parsed)) { + return numeralValue; + } else if (numeralValue === null) { + return parsed; + } else { + return Math.max(numeralValue, parsed); + } + } } export const numeralWrapper = new NumeralFormatter();