Forminator calculations output

I have a calculated field which is generating cost of service for me, but this is outputting a decimal value such as “5.4”, where Ideally I want it to say 5.40.

Also, if the price is £6 I would like to show 6.00. Is it possible?

  • Neel Gajjar
    • Staff

    Hello,

    how are you doing today?

    You need to add an extra piece of code to achieve this functionality.

    You need to create a mu-plugin for you to achieve the new folder system that you want.

    How to install:

    Always make sure to keep a backup of your site before changing/adding custom code.

    1] Navigate to your /wp-content/ directory and create a new one named mu-plugins if it doesn't exist.

    2] Download the attached .zip and extract it. You will find a file named forminator-decimal.php

    3] Upload the .php file into the mu-plugins directory.

    4] The final path should look like /wp-content/mu-plugins/forminator-decimal.php

    5] Everything should work after that automatically.

    Let me know how it goes.

    I'm looking forward to hearing from you and resolving this issue as soon as possible.

    Kind Regards,

    Neel Gajjar

    This is the code.

    <?php
    add_action( 'forminator_render_form_markup', function( $html, $form_fields, $form_type, $form_settings, $form_design, $render_id ){

    ob_start();
    ?>
    <script type="text/javascript">
    (($,d)=>{

    if ( window.wpmudev_forminator_fixed_calculation_digits ) {

    return;
    }

    window.wpmudev_forminator_fixed_calculation_digits = {

    init: function() {

    $(d).ajaxComplete( function( event, xhr, settings ) {
    const action = wpmudev_forminator_fixed_calculation_digits.get_action( 'action', settings.data );

    if ( 'forminator_load_cform' == action ) {

    $( '.forminator-calculation' ).on( 'change', function(){
    this.value = parseFloat( this.value ).toFixed( 2 );
    } );

    }
    });
    },

    get_action: function( name, url ) {
    if ( ! url ) {
    return '';
    }
    name = name.replace(/[[]]/g, "\$&");
    var regex = new RegExp(name + "(=([^&#]*)|&|#|$)"),
    results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent( results[2].replace(/+/g, " ") );
    }
    };

    $(d).ready( function(){
    wpmudev_forminator_fixed_calculation_digits.init();
    } );
    })(jQuery,document);
    </script>
    <?php
    return $html . ob_get_clean();
    }, 20, 6 );

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.