Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not throw on parseUnits if input truncatable #1019

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/bignumber/src.ts/fixednumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ export function parseFixed(value: string, decimals?: BigNumberish): BigNumber {

// Prevent underflow
if (fraction.length > multiplier.length - 1) {
throwFault("fractional component exceeds decimals", "underflow", "parseFixed");
// handle case 123.45600000
if (fraction.slice(multiplier.length, fraction.length) !== '0'.repeat(fraction.length-multiplier.length-1)) {
throwFault("fractional component exceeds decimals", "underflow", "parseFixed");
} else {
fraction = fraction.slice(0, multiplier.length)
}
}

// Fully pad the string with zeros to get to wei
Expand Down