How do I divide one field by another?

I want to show discount in percent, so I have two fields: old price and new price. Trying to show discount like this, but it returns zero:

<?php
$old = $album->price();
$new = $album->newprice();

$discount = (($new-$old)/$old)*100;
echo $discount.'%';
?>

price and newprice field type is number

Try

<?php
$old = $album->price()->toFloat();
$new = $album->newprice()->toFloat();

$discount = (($new-$old)/$old)*100;
echo $discount.'%';
1 Like

Ah, ok, clear now, thanks a lot!