Skip to content

Commit

Permalink
CakeNumber::formatDelta
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Sep 28, 2012
1 parent 6ea5877 commit e88dcd2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions en/appendices/2-3-migration-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ CakeNumber
----------

- :php:meth:`CakeNumber::fromReadableSize()` was added.
- :php:meth:`CakeNumber::formatDelta()` was added.

Folder
------
Expand Down
50 changes: 48 additions & 2 deletions en/core-utility-libraries/number.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ automatically echo the output into the view.
echo CakeNumber::currency('1234.56', 'FOO');

.. php:method:: addFormat(string $formatName, array $options)
:param string $formatName: The format name to be used in the future
:param array $options: The array of options for this format. Uses the
same ``$options`` keys as :php:meth:`CakeNumber::currency()`.
Expand Down Expand Up @@ -211,7 +211,7 @@ automatically echo the output into the view.

.. php:method:: toReadableSize(string $dataSize)
:param string $data_size: The number of bytes to make readable.
:param string $data_size: The number of bytes to make readable.

This method formats data sizes in human readable forms. It provides
a shortcut way to convert bytes to KB, MB, GB, and TB. The size is
Expand Down Expand Up @@ -292,6 +292,52 @@ automatically echo the output into the view.
));
// output '¥ 123,456.79'

.. php:method:: formatDelta(mixed $number, mixed $options=array())
This method displays differences in value as a signed number::

<?php
// called as NumberHelper
$this->Number->format($number, $options);

// called as CakeNumber
CakeNumber::format($number, $options);

The $number parameter is the number that you are planning on
formatting for output. With no $options supplied, the number
1236.334 would output as 1,236. Note that the default precision is
zero decimal places.

The $options parameter takes the same keys as :php:meth:`CakeNumber::format()` itself:

- places (integer): the amount of desired precision
- before (string): to be put before the outputted number
- after (string): to be put after the outputted number
- decimals (string): used to delimit the decimal places in a
number
- thousands (string): used to mark off thousand, millions, …
places

Example::

<?php
// called as NumberHelper
echo $this->Number->formatDelta('123456.7890', array(
'places' => 2,
'decimals' => '.',
'thousands' => ','
));
// output '+123,456.79'

// called as CakeNumber
App::uses('CakeNumber', 'Utility');
echo CakeNumber::formatDelta('123456.7890', array(
'places' => 2,
'decimals' => '.',
'thousands' => ','
));
// output '+123,456.79'

.. end-cakenumber
.. meta::
Expand Down

0 comments on commit e88dcd2

Please sign in to comment.