| 1 |
lars |
1 |
<?php
|
|
|
2 |
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
|
|
3 |
// +----------------------------------------------------------------------+
|
|
|
4 |
// | PHP version 4.0 |
|
|
|
5 |
// +----------------------------------------------------------------------+
|
|
|
6 |
// | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group |
|
|
|
7 |
// +----------------------------------------------------------------------+
|
|
|
8 |
// | This source file is subject to version 2.0 of the PHP license, |
|
|
|
9 |
// | that is bundled with this package in the file LICENSE, and is |
|
|
|
10 |
// | available at through the world-wide-web at |
|
|
|
11 |
// | http://www.php.net/license/2_02.txt. |
|
|
|
12 |
// | If you did not receive a copy of the PHP license and are unable to |
|
|
|
13 |
// | obtain it through the world-wide-web, please send a note to |
|
|
|
14 |
// | license@php.net so we can mail you a copy immediately. |
|
|
|
15 |
// +----------------------------------------------------------------------+
|
|
|
16 |
// | Authors: Wolfram Kriesing <wk@visionp.de> |
|
|
|
17 |
// | |
|
|
|
18 |
// +----------------------------------------------------------------------+//
|
|
|
19 |
// $Id: Number.php 145353 2003-12-01 23:05:56Z cain $
|
|
|
20 |
|
|
|
21 |
require_once 'I18N/Format.php';
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* this is just a basic implementation for now, but one day
|
|
|
25 |
* this
|
|
|
26 |
* http://java.sun.com/docs/books/tutorial/i18n/format/numberpattern.html
|
|
|
27 |
* should be implemented, anyone with a DecimalFormat-class please step forward :-)
|
|
|
28 |
*
|
|
|
29 |
* @package I18N
|
|
|
30 |
*
|
|
|
31 |
*/
|
|
|
32 |
class I18N_Number extends I18N_Format
|
|
|
33 |
{
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* this var contains the current locale this instace works with
|
|
|
37 |
*
|
|
|
38 |
* @access protected
|
|
|
39 |
* @var string this is a string like 'de_DE' or 'en_US', etc.
|
|
|
40 |
*/
|
|
|
41 |
var $_locale;
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* the locale object which contains all the formatting specs
|
|
|
45 |
*
|
|
|
46 |
* @access protected
|
|
|
47 |
* @var object
|
|
|
48 |
*/
|
|
|
49 |
var $_localeObj = null;
|
|
|
50 |
|
|
|
51 |
var $_currentFormat = I18N_NUMBER_FLOAT;
|
|
|
52 |
// var $_currentPercentFormat = I18N_NUMBER_FLOAT;
|
|
|
53 |
|
|
|
54 |
var $_customFormats = array();
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* format a given number depending on the locale
|
|
|
58 |
*
|
|
|
59 |
* @version 02/11/22
|
|
|
60 |
* @author Wolfram Kriesing <wolfram@kriesing.de>
|
|
|
61 |
* @param mixed the number to be formatted
|
|
|
62 |
* @return string the formatted number
|
|
|
63 |
*/
|
|
|
64 |
function format( $number , $format=null )
|
|
|
65 |
{
|
|
|
66 |
if( $format == null ){
|
|
|
67 |
$format = $this->getFormat();
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
// handle custom formats too
|
|
|
71 |
if ($format >= I18N_CUSTOM_FORMATS_OFFSET) {
|
|
|
72 |
if (isset($this->_customFormats[$format])) {
|
|
|
73 |
$numberFormat = $this->_customFormats[$format];
|
|
|
74 |
}
|
|
|
75 |
} else {
|
|
|
76 |
$numberFormat = $this->_localeObj->numberFormat[$format];
|
|
|
77 |
}
|
|
|
78 |
return call_user_func_array( 'number_format' , array_merge( array($number),$numberFormat) );
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
function formatPercent()
|
|
|
84 |
{
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
}
|
|
|
88 |
?>
|