for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace hiqdev\php\units\formatters;
use hiqdev\php\units\FormatterInterface;
use hiqdev\php\units\Quantity;
/**
* Class SimpleFormatter
*
* @author Dmytro Naumenko <[email protected]>
*/
class SimpleFormatter implements FormatterInterface
{
* @param Quantity $quantity
* @return string
public function format(Quantity $quantity): string
return $this->formatQuantity($quantity) . ' ' . $quantity->getUnit()->getName();
}
private function formatQuantity(Quantity $quantity): string
$value = (float)$quantity->getQuantity();
return rtrim(rtrim(number_format($value, 6, '.', ' '), '0'), '.');