1
votes

does anyone know if it's possible to divide two values?

For example:

product price / unit price = wanted result

Product price:

      {{price.without_tax.formatted}}

A filter for unit price

      {{#filter custom_fields 'Units per case' property='name'}}
      <p>{{ value}}</p>
      {{/filter}}

If I am to use something like:

    {{#filter custom_fields 'Units per case' property='name'}}
           <p>{{toFixed price.without_tax.formatted divide value}}</p>
     {{/filter}} 

I get a 0. If I don't include toFixed then nothing shows up. Not sure how to proceed. Please help.

(I know this is some crazy code but I don't know better.)

1

1 Answers

1
votes

I'm seeing a number of issues. Try this:

{{#filter custom_fields 'Units per case' property='name'}}
       <p>{{toFixed (divide ../price.without_tax.value value) 2}}</p>
{{/filter}} 
  • Use price.without_tax.value instead of price.without_tax.formatted so it returns a number instead of a string.
  • Add ../ to the price object since it is nested inside {{filter}}.
  • The divide syntax is {{divide a b}}.
  • I added a parameter "2" to {{toFixed}} so it shows the result with 2 decimal places.