We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28173
    • 409 Posts
    Hi,

    On a website, I have a TV for the price without VTA
    I want to make a calculation of the price VTA included

    For example :
    - my TV [[*price]] content is 1000
    - the VTA rate is 19.6%
    - I want to insert automaticaly on a doc the result of [[*price]]x1.196

    Is that possible with MODx ?
      • 11076
      • 159 Posts
      you can use an output filter
      http://rtfm.modx.com//display/revolution20/Input+and+Output+Filters
      what you asked for can be simply accomplished with the multiply/mpy filter.

      take in mind that if you want to use the combined ’math’ filter:
      math Returns the result of an advanced calculation (expensive on processor. not recommended).
        Michael Shraibman( gOmp)  | Freelance Design & Development | wink  impossible is nothing...
        • 28173
        • 409 Posts
        OK thanks for the tip smiley
          • 28173
          • 409 Posts
          Hummm I can multiply by 3, but not by 1.196 !
          [[*Price]] return 1000
          [[*Price:mpy=`3`]] return 3000
          [[*Price:mpy=`1.196`] return 1000 !!!

          What’s wrong ?
            • 11076
            • 159 Posts
            i think it’s because the filter uses intval() function to ensure an integer number is given instead of using is_numeric().

            but you can use your own filter snippet to support float vars as well.
            here’s mpyfs (multiply float/full support) snippet. it’s the simplest.
            Returns the input multiplied by any number (with float support), Rounds the result to 2 digits.

            <?php
            $output = '';
            
            if (!empty($input) && is_numeric($input) && !empty($options) && is_numeric($options)) { 
            	/* Multiply & Round the Float to 2 Digits */
            	$output = round($input * $options, 2);
            }
            else
            	$output = $input;
            
            return $output;
            ?>


            :)

            and then simply use it as: [[*Price:mpyfs=`1.196`]] | Result: 1196 when price set to 1000

            hope it helps..
              Michael Shraibman( gOmp)  | Freelance Design & Development | wink  impossible is nothing...
              • 28173
              • 409 Posts
              Perfect that’s working !

              Thanks a lot gOmp smiley
                • 11076
                • 159 Posts
                np, your welcome, glad it helped.
                  Michael Shraibman( gOmp)  | Freelance Design & Development | wink  impossible is nothing...
                  • 19072
                  • 1 Posts
                  Hello GOmp.
                  thank you for this information.
                  i was looking for a solution to this calcul.
                  thank you again.
                    • 3749
                    • 24,544 Posts
                    FYI, I think it will be faster if you use the same snippet and this tag:

                    [[!mpyfs? $input=`[[*Price]]`]]
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting