Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

582
Views
Error: fractional component exceeds decimals in eithersJS

Why does the following return a fractional component error for exceeding decimals? It only seems to trigger on low balance.

If my balance is 0.1 ether or BNB I don't see an error but if my balance is 0.0001 I would see this error

Error: fractional component exceeds decimals

var account = accounts[0]
var yourBalance = await provider.getBalance(account)
var fixedBalance= ethers.FixedNumber.fromValue(yourbalance , 18);
var stakedAmount = (fixedBalance * 0.50).toString();
var finalOutput = ethers.utils.parseUnits(stakedAmount , 18);  //this returns Error: fractional component exceeds decimals
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use toFixed(n)

var stakedAmount = (fixedBalance * 0.50).toFixed(6) ;

n is defined as the maximum amount of precision you need in your decimal places.

I picked 6 arbitrarily but this comment suggests you could potentially go up to 18?

toFixed(n) will also convert your number to a string so you can removetoString().

I think it's because your floating point number has too many decimal places to be represented by BigNumber thus, you need to truncate the precision of your decimal places.

For posterity and people coming here via search engines, the full traceback I received was:

Error: fractional component exceeds decimals
 (fault="underflow", operation="parseFixed", code=NUMERIC_FAULT, version=bignumber/5.5.0)

It's very interesting because I literally had a similar error just now. A couple of hours after you.

This issue, this issue and this code snippet helped me figure it out.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!