Skip to content

NumberHelper

class NumberHelper(View $view, array $settings = array())

The NumberHelper contains convenient methods that enable display numbers in common formats in your views. These methods include ways to format currency, percentages, data sizes, format numbers to specific precisions and also to give you more flexibility with formatting numbers.

Changed in version 2.1

NumberHelper have been refactored into CakeNumber class to allow easier use outside of the View layer. Within a view, these methods are accessible via the NumberHelper class and you can call it as you would call a normal helper method: $this->Number->method($args);.

All of these functions return the formatted number; They do not automatically echo the output into the view.

method CakeNumber::currency(float $number, string $currency = 'USD', array $options = array())

method CakeNumber::defaultCurrency(string $currency)

method CakeNumber::addFormat(string $formatName, array $options)

method CakeNumber::precision(mixed $number, int $precision = 3)

method CakeNumber::toPercentage(mixed $number, int $precision = 2, array $options = array())

method CakeNumber::fromReadableSize(string $size, $default)

method CakeNumber::toReadableSize(string $dataSize)

method CakeNumber::format(mixed $number, mixed $options=false)

method CakeNumber::formatDelta(mixed $number, mixed $options=array())

WARNING

Since 2.4 the symbols are now UTF-8. Please see the migration guide for details if you run a non-UTF-8 app.

Released under the MIT License.