Skip to content

Extend CFormatter: formatCurrency, formatPercentage, formatDecimal #254

Closed
qiangxue opened this Issue Feb 15, 2012 · 3 comments

4 participants

@qiangxue
Yii Software LLC member

What version of the product are you using? On what operating system?
1.1.8 (Ubuntu Hardy)

Please provide any additional information below.
Currently when using the CGridView widget, columns can be formatted using CFormatter instances. While this class provides a fair amount of predefined functions, it would be quite convenient if it'd also support the functions of the CNumberFormatter class. Unfortunately these classes are currently incompatible: the CNumberFormatter suggests it may be extended from CFormatter but there is no common base class.

Eventually it will probably be a good idea to create a common base class for the two (is there a good reason why there is none?), but a quick solution is to just extend CFormatter with a number of functions which call the appropriate CNumberFormatter functions. I've created and attached a patch (against the current SVN, r3430) which does exactly this.

Please let me know what you think about this.

Migrated from http://code.google.com/p/yii/issues/detail?id=2925


earlier comments

qiang.xue said, at 2012-01-01T03:37:10.000Z:

set for 1.1.10 milestone

qiang.xue said, at 2012-01-01T03:37:36.000Z:

set for 1.1.10 milestone

@cebe
Yii Software LLC member
cebe commented Mar 12, 2012

@cebe will try to work on this.

@jeicd
jeicd commented Mar 13, 2012

I suggest to add format size methods, something like this:

    public $sizeFormat=array('base'=>1024, 'decimals'=>2);

    /**
     * Formats the value as a size in human readable form.
     * @params integer value to be formatted
     * @return string the formatted result
     */
    public function formatSize($value)
    {
        $units=array('B', 'KB', 'MB', 'GB', 'TB');
        $base=$this->sizeFormat['base'];
        for($i=0; $base<=$value; $i++)
            $value=$value / $base;
        return round($value, $this->sizeFormat['decimals']).$units[$i];
    }
@cebe
Yii Software LLC member
cebe commented Mar 13, 2012

@jeicd we have this suggestions already in #192 and problems with it are discussed there.

@samdark samdark closed this Nov 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.