title: Calculate Prorated Rate For Stripe Using Billing Cycle Anchor
body: <p>I'm creating a prorated charge for the 1st subscription month using <strong>billing_cycle_anchor</strong> to make sure that the 1st full invoice is charged on the 1st of the next month.</p>
  
  <p>This part works well but then Stripe calculates a prorated rate for the current invoice to be between (right now) &amp; the future billing date.</p>
  
  <p>How can I calculate and show this prorated charge to my customer before actually charging their card?</p>
  
  <p>Currently we are using the below formula to calculate the current proration amount but its not exact. Our formula displayed <strong>3.54 USD</strong> but Stripe ended up charging <strong>3.87 USD</strong></p>
  
  <pre><code>async function getThisMonth(pmtdata) {
      let now = Date.now();
      var lastday = function(y,m){
          return  new Date(y, m +1, 0).getDate();
      }
      let seconds = now / 1000;
      let year = new Date().getFullYear();
      let month = new Date().getMonth();
      if(month &lt;= 10) {
          let date = lastday(year,month);
          let l1 = 86400 * Number(date);
          let l2 = Number(pmtdata.numberPrice) / l1;
          let todayD = new Date().getUTCDate();
          let l3 = date - todayD;
          let l4 = 86400 * l3;
          let finalOut = Number(l2 * l4).toFixed(2);
          $w("#thisMonth").text = finalOut + ' ' + pmtdata.currency;
          chargeable = finalOut;
      } else if(month === 11) {
          month = await -1;
          let date = lastday(year,month);
          let l1 = 86400 * Number(date);
          let l2 = Number(pmtdata.numberPrice) / l1;
          let todayD = new Date().getUTCDate();
          let l3 = date - todayD;
          let l4 = 86400 * l3;
          let finalOut = Number(l2 * l4).toFixed(2);
          $w("#thisMonth").text = finalOut + ' ' + pmtdata.currency;
          chargeable = finalOut;
      }
  }
  </code></pre>
  
  <p>pmtdata carries the monthly price and currency</p>