<?php
namespace Newland\NeosViewHelpers\ViewHelpers\Math;

/*
 * This file is part of the "neos-viewhelpers" package.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 */

use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;

/**
 * Simple division viewhelper that was introduced because in certain circumstances the
 * fluid builtin division (using `{foo.bar / 1000}`) will throw an exception.
 *
 * @example
 * <vh:math.divide value="{foo.bar}" by="1000" />
 *
 * @example
 * {foo.bar -> vh:math.divide(by: 1000) -> vh:math.round(precision: 2)}
 */
class DivideViewHelper extends AbstractViewHelper
{

    /**
     * @param float $by
     * @param float|null $value
     * @return float
     */
    public function render(float $by, float $value = null): float
    {
        $value = $value ?? (float) $this->renderChildren();
        return $value / $by;
    }
}
