mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-23 08:03:48 +01:00
Added accepting numbers in 1b format to faction donations
This commit is contained in:
parent
13206a8c3e
commit
68eb68a89e
@ -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<IProps, IState> {
|
||||
}
|
||||
|
||||
handleChange(e: React.ChangeEvent<HTMLInputElement>): void {
|
||||
const amt = parseFloat(e.target.value);
|
||||
const amt = numeralWrapper.parse(e.target.value);
|
||||
|
||||
if (isNaN(amt)) {
|
||||
this.setState({
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user