Title: Template request excel PV function
Last modified: November 12, 2018

---

# Template request excel PV function

 *  Resolved [randrewsv](https://wordpress.org/support/users/randrewsv/)
 * (@randrewsv)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/template-request-excel-pv-function/)
 * Hello
    Any way you could add the PV Excel function to the commom Functions that
   you have??
 * Here is a Code Pen i made with JS
    [https://codepen.io/rafael-andrews/pen/dQOWKa](https://codepen.io/rafael-andrews/pen/dQOWKa)
   But i getting a hard time implementing this
 * any way you could help me?
 * Thanks and Regards!
 * Rafael.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [EDGARROJAS](https://wordpress.org/support/users/edgarrojas/)
 * (@edgarrojas)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/template-request-excel-pv-function/#post-10872151)
 * Hello!
 * According to [https://gist.github.com/ghalimi/4638848](https://gist.github.com/ghalimi/4638848),
   this is the formula for pv.
 *     ```
       function PV(rate, periods, payment, future, type) {
         // Initialize type
         var type = (typeof type === 'undefined') ? 0 : type;
   
         // Evaluate rate and periods (TODO: replace with secure expression evaluator)
         rate = eval(rate);
         periods = eval(periods);
   
         // Return present value
         if (rate === 0) {
           return - payment * periods - future;
         } else {
           return (((1 - Math.pow(1 + rate, periods)) / rate) * payment * (1 +rate * type) - future) / Math.pow(1 + rate, periods);
         }
       }
       ```
   
 * So you just need to put this function at the top of the formula and bellow it
   you can use it. example:
 *     ```
       function PV(rate, periods, payment, future, type) {
         // Initialize type
         var type = (typeof type === 'undefined') ? 0 : type;
   
         // Evaluate rate and periods (TODO: replace with secure expression evaluator)
         rate = eval(rate);
         periods = eval(periods);
   
         // Return present value
         if (rate === 0) {
           return - payment * periods - future;
         } else {
           return (((1 - Math.pow(1 + rate, periods)) / rate) * payment * (1 +rate * type) - future) / Math.pow(1 + rate, periods);
         }
       }
   
       return PV(0.0521/1,11,[paymenttotal],0,0);
       ```
   
 * In this example you could replace [paymenttotal] for the field that has the total
   value of your form.
 * Regards!
    -  This reply was modified 7 years, 7 months ago by [EDGARROJAS](https://wordpress.org/support/users/edgarrojas/).
    -  This reply was modified 7 years, 7 months ago by [EDGARROJAS](https://wordpress.org/support/users/edgarrojas/).
 *  Thread Starter [randrewsv](https://wordpress.org/support/users/randrewsv/)
 * (@randrewsv)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/template-request-excel-pv-function/#post-10872844)
 * Hello Edgar
    Thanks you for your reply
 * I’m having a hard time implementing this, i’m a newbie in your plugin
    do i need
   to define the variables?
 *     ```
       (function PV(rate, periods, payment, future, type) {
          // Initialize type
             rate =$$field_rate$$/100;
           periods = $$field_periods$$;
           payment = $$field_payment$$;
           future = $$field_future$$;
           type = $$field_type$$;
         var type = (typeof type === 'undefined') ? 0 : type;
   
         // Evaluate rate and periods (TODO: replace with secure expression evaluator)
   
         // Return present value
         if (rate === 0) {
           return -payment * periods - future;
         } else {
           return (((1 -Math.pow(1 + rate, periods)) / rate) * payment * (1 +rate * type) -future) / Math.pow(1 + rate, periods);
         }
       return PV(0.0521/1,11,[$$field_total$$],0,0);
       })();
       ```
   
 * i’m getting several errors in console and i dont know what i’m doing wrong
    can
   you please help me?
 * Regards!
 *  Plugin Author [EDGARROJAS](https://wordpress.org/support/users/edgarrojas/)
 * (@edgarrojas)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/template-request-excel-pv-function/#post-10875449)
 * Hello!
 * I think it actually should be something like` this:
 *     ```
       function PV(rate, periods, payment, future, type) {
         type = (typeof type === 'undefined') ? 0 : type;  
         if (rate === 0) {
           return -payment * periods - future;
         } else {
           return (((1 - Math.pow(1 + rate, periods)) / rate) * payment * (1 +rate * type) - future) / Math.pow(1 + rate, periods);
         }
   
       }
       return PV($$field_rnField3$$,$$field_rnField4$$,$$field_rnField1$$,$$field_rnField5$$,0);
       ```
   
 * Regards!
 *  Thread Starter [randrewsv](https://wordpress.org/support/users/randrewsv/)
 * (@randrewsv)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/template-request-excel-pv-function/#post-10877637)
 * Works perfect
    Thanks You
 * kind Regards!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Template request excel PV function’ is closed to new replies.

 * ![](https://ps.w.org/smart-forms/assets/icon-256x256.jpg?rev=1226707)
 * [Smart Forms - when you need more than just a contact form](https://wordpress.org/plugins/smart-forms/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/smart-forms/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/smart-forms/)
 * [Active Topics](https://wordpress.org/support/plugin/smart-forms/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/smart-forms/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/smart-forms/reviews/)

## Tags

 * [functions](https://wordpress.org/support/topic-tag/functions/)

 * 4 replies
 * 2 participants
 * Last reply from: [randrewsv](https://wordpress.org/support/users/randrewsv/)
 * Last activity: [7 years, 7 months ago](https://wordpress.org/support/topic/template-request-excel-pv-function/#post-10877637)
 * Status: resolved