for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Benrowe\Formatter\Providers;
use Benrowe\Formatter\AbstractFormatterProvider;
/**
* @package Benrowe\Formatter
*/
class Numbers extends AbstractFormatterProvider
{
* Display the value as currency
*
* @param mixed $value
* @return string
public function asCurrency($value)
if ($value === null) {
return $this->nullValue;
}
$value = $this->normaliseValue($value);
$prefix = '$';
if ($value < 0) {
$prefix = '-$';
$value *= -1;
$newValue = number_format($value, 2);
return $prefix.$newValue;
* Displays the number as an unsigned value
* @return double|int|string
public function asUnsigned($value)
return $value;
* Format the supplied value as a number
public function asNumber($value)
return $this->normaliseValue($value);
* Convert the supplied value into a valid number value
* @return float|int
private function normaliseValue($value)
if (!is_numeric($value)) {
$value = 0;
// cast the value to int or float based on its true type
return (float)$value === (float)(int)$value ? (int)$value : (float)$value;