title: Getting correct decimals in ethers.io library, using getAmountsOut() ABI
body: <p>I am using getAmountsOut() interface to get the current PancakeSwap price of a random BSC token.</p>
  <p>The digits I get back do match Pancakeswap's quote (roughly), but I seem to be unable to display it in a human-readable format with the correct decimals.</p>
  <pre><code>import ethers from &quot;ethers&quot;;
  
  // ...open factory, account etc....
  
  const TOKEN_WBNB_ADDR = &quot;0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c&quot;; // WBNB
  const TOKEN_FEG_ADDR = &quot;0xacfc95585d80ab62f67a14c566c1b7a49fe91167&quot;; // Token
  const router = new ethers.Contract(
      factory,    // PancakeSwap V2 factory
      ['function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)'],
      account,
  );
  
  // how many WBNBs would we get for 1 FEG?
  const wbnbsPerToken = await router.getAmountsOut(
      ethers.utils.parseUnits(&quot;1.00&quot;, 9), // token has 9 decimals
      [TOKEN_FEG_ADDR, TOKEN_WBNB_ADDR]);
  
  console.log(`${ethers.utils.formatUnits(wbnbsPerToken[1], 9)} WBNB per FEG`);
  
  // My script's output:   0.018870301 WBNB per FEG
  // PancakeSwap's output: 0.0000000000190529 WBNB per FEG
  </code></pre>
  <p><strong>Question 1:</strong> Ignoring the slight price difference, why are my decimals off so bad (by 9)?</p>
  <p><strong>Question 2:</strong> Why <em>do</em> I have a price difference? Something with slippage? Pancakeswap's quotes of that coin are consistently a bit higher. It's not a timing thing, it's consistent.</p>
  <p>Or am I calculating the quote wrong altogether??</p>
  <p>Thanks a bunch in advance!</p>