Maybe I'm overlooking something, but can't find a solution on the interwebs..
I have 2 (money) fields: product.price and product.oldPrice
When I try to calculate the discount like this (I'm aware that this simple approach shouldn't work):
{% set discount = product.price / product.oldPrice * 100 %}
I get this error message: Unsupported operand types: Money\Money / Money\Money
And when I try calling it as a 'float':
{% set discount = product.price|number_format(2) / product.oldPrice|number_format(2) * 100 %}
I get this error message: Object of class Money\Money could not be converted to float
The only solution I can think of is changing the field type in 'Float', but that would make things more difficult.
I also tried Martin Spains solution, who suggested to call the value of the objects like this:
{% set discount = product.price.value / product.oldPrice.value * 100 %}
But then I get this error:
Neither the property "value" nor one of the methods "value()", "getvalue()"/"isvalue()"/"hasvalue()" or "__call()" exist and have public access in class "Money\Money".
I hope someone has a solution for me
product.price.value
to get the value itself rather than the field model.