本文整理汇总了PHP中Zend_Locale_Format::toInteger方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Locale_Format::toInteger方法的具体用法?PHP Zend_Locale_Format::toInteger怎么用?PHP Zend_Locale_Format::toInteger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Locale_Format
的用法示例。
在下文中一共展示了Zend_Locale_Format::toInteger方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filter
/**
* Defined by Zend_Filter_Interface
*
* Normalizes the given input
*
* @param string $value Value to normalized
* @return string|array The normalized value
*/
public function filter($value)
{
if (is_array($value)) {
require_once 'Zend/Date.php';
$date = new Zend_Date($value, $this->_options['locale']);
return $date->toString($this->_options['date_format']);
} else {
if ($this->_options['precision'] === 0) {
return Zend_Locale_Format::toInteger($value, $this->_options);
} else {
if ($this->_options['precision'] === null) {
return Zend_Locale_Format::toFloat($value, $this->_options);
}
}
}
return Zend_Locale_Format::toNumber($value, $this->_options);
}
示例2: getByteSized
/**
* Format in drive units
*
* @param int $size
* @return string
*/
public static function getByteSized($size)
{
$units = array('', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb');
$power = $size > 0 ? floor(log($size, 1024)) : 0;
return \Zend_Locale_Format::toInteger($size / pow(1024, $power)) . ' ' . $units[$power];
}
示例3: type_to_str
/**
* переводит значение заданного типа в строку
*
* @param mixed $data значение, которое нужно сконвертировать
* @param string $type тип данных ('bool','date')
* @param int $precision_default задание точного количества знаков после запятой
* @return string полученная строка, представляющая данные
*/
function type_to_str($data, $type, $precision_default = -1)
{
switch ($type) {
case 'encode':
return htmlentities($data, ENT_QUOTES, 'utf-8');
case 'translate':
return __($data);
case "integer":
/**
* Локально пустые значения спокойно форматируется зендом в 0,
* но на сервере, на orbitscipts.com? после форматирования пустого значение,
* оно так и остаётся пустое. Я не знаю почему.
*/
if (is_null($data) || $data == '') {
$data = 0;
}
$res = Zend_Locale_Format::toInteger($data, array('locale' => get_instance()->locale));
return $res;
case "float":
$precision = 2;
/**
* Определние нужной точности для денег
*/
if ($precision_default < 0) {
$vals = explode('.', strval((double) $data));
if (isset($vals[1])) {
$len = strlen($vals[1]);
if ($len > 3) {
$precision = 4;
} elseif ($len > 2) {
$precision = 3;
}
}
} else {
$precision = $precision_default;
}
return number_format($data, $precision, '.', '');
//return Zend_Locale_Format::toFloat($data, array('locale'=> get_instance()->locale));
//return Zend_Locale_Format::toFloat($data, array('locale'=> get_instance()->locale));
case 'procent':
return type_to_str($data, 'float', 2) . ' %';
case "money":
//return str_replace('%', type_to_str($data, 'float'), get_format('money'));
if (is_null($data)) {
$data = 0;
}
/**
* @todo Возможно прийдётся определять тип валюты как-то глобально,
* когда понадобится использовать что-нибудь отличное от доллара.
*/
try {
$currency = new Zend_Currency(get_instance()->locale, 'USD');
} catch (Zend_Currency_Exception $e) {
$currency = new Zend_Currency(get_instance()->default_locale, 'USD');
}
$precision = 2;
/**
* Определние нужной точности для денег
*/
$vals = explode('.', strval((double) $data));
if (isset($vals[1])) {
$len = strlen($vals[1]);
}
$currency->setFormat(array('precision' => $precision));
try {
$value = trim($currency->toCurrency($data));
/**
* проверка preg_matchем нужна потмоу что, например в китайском валюта отображается
* как: US$0.00
*/
if (get_instance()->locale != 'en_US' && preg_match('|^[0-9,\\.\\$\\s\\xc2\\xa0]+$|', $value, $matches)) {
$value = '$' . trim(str_replace('$', '', $value));
}
} catch (Exception $e) {
$value = '0.00';
}
return $value;
case "nonzeromoney":
if ($data == 0) {
return "—";
}
return type_to_str($data, "money");
case "mysqldate":
$data = mktime(0, 0, 0, substr($data, 5, 2), substr($data, 8, 2), substr($data, 0, 4));
return date(get_date_format(), $data);
case "mysqlfloat":
//return str_replace(',','.',$data);
return number_format($data, 8, '.', '');
case 'databasedate':
return date("Y-m-d", $data);
case 'databasedatetime':
return date("Y-m-d H:i:s", $data);
//.........这里部分代码省略.........
示例4: testtoInteger
/**
* test toInteger
* expected string
*/
public function testtoInteger()
{
$this->assertEquals('0', Zend_Locale_Format::toInteger(0 ));
$this->assertEquals('0', Zend_Locale_Format::toInteger(0, array('locale' => 'de')));
$options = array('locale' => 'de_AT');
$this->assertEquals( '0', Zend_Locale_Format::toInteger( 0, $options));
$this->assertEquals( '−1.234.567', Zend_Locale_Format::toInteger(-1234567, $options));
$this->assertEquals( '1.234.567', Zend_Locale_Format::toInteger( 1234567, $options));
$this->assertEquals( '0', Zend_Locale_Format::toInteger( 0.1234567, $options));
$this->assertEquals( '−1.234.567', Zend_Locale_Format::toInteger(-1234567.12345, $options));
$this->assertEquals( '1.234.567', Zend_Locale_Format::toInteger( 1234567.12345, $options));
$this->assertEquals( '1234567', Zend_Locale_Format::toInteger( 1234567.12345, array('locale' => 'ar_QA')));
$this->assertEquals( '1234567-', Zend_Locale_Format::toInteger(-1234567.12345, array('locale' => 'ar_QA')));
$this->assertEquals( '12,34,567', Zend_Locale_Format::toInteger( 1234567.12345, array('locale' => 'dz_BT')));
$this->assertEquals('-(1.234.567)', Zend_Locale_Format::toInteger(-1234567.12345, array('locale' => 'mk_MK')));
}
示例5: testShortNotation
public function testShortNotation()
{
$this->assertEquals(0.12345, Zend_Locale_Format::getNumber(0.12345));
$options = array('locale' => 'de');
$this->assertEquals(0.12345, Zend_Locale_Format::getNumber(',12345', $options));
$options = array('locale' => 'de_AT');
$this->assertEquals(0.12345, Zend_Locale_Format::getNumber(',12345', $options));
$this->assertEquals('0,75', Zend_Locale_Format::toNumber(0.75, array('locale' => 'de_DE', 'precision' => 2)));
$this->assertTrue(Zend_Locale_Format::isNumber(',12345', array('locale' => 'de_AT')));
$this->assertEquals(0.12345, Zend_Locale_Format::getFloat(0.12345));
$options = array('locale' => 'de');
$this->assertEquals(0.12345, Zend_Locale_Format::getFloat(',12345', $options));
$options = array('locale' => 'de_AT');
$this->assertEquals(0.12345, Zend_Locale_Format::getFloat(',12345', $options));
$options = array('locale' => 'de_AT');
$this->assertEquals('0,12345', Zend_Locale_Format::toFloat(0.12345, $options));
$options = array('locale' => 'ar_QA');
$this->assertEquals('0,12345', Zend_Locale_Format::toFloat(0.12345, $options));
$this->assertTrue(Zend_Locale_Format::isFloat(',12345', array('locale' => 'de_AT')));
$this->assertEquals(0, Zend_Locale_Format::getInteger(0.1234567));
$options = array('locale' => 'de');
$this->assertEquals(0, Zend_Locale_Format::getInteger(',12345', $options));
$options = array('locale' => 'de_AT');
$this->assertEquals(0, Zend_Locale_Format::getInteger(',12345', $options));
$this->assertEquals('0', Zend_Locale_Format::toInteger(0.123, array('locale' => 'de')));
$options = array('locale' => 'de_AT');
$this->assertEquals('0', Zend_Locale_Format::toInteger(0.12345, $options));
$this->assertFalse(Zend_Locale_Format::isInteger(',12345', array('locale' => 'de_AT')));
$options = array('locale' => 'de_AT');
$this->assertEquals('0,567', Zend_Locale_Format::toNumber(0.5669999999999999, $options));
}
示例6: testtoInteger
/**
* test toInteger
* expected string
*/
public function testtoInteger()
{
$this->assertEquals(Zend_Locale_Format::toInteger(0), '0', "string 0 expected");
$this->assertEquals(Zend_Locale_Format::toInteger(0, array('locale' => 'de')), '0', "string 0 expected");
$options = array('locale' => 'de_AT');
$this->assertEquals(Zend_Locale_Format::toInteger(0, $options), '0', "string 0 expected");
$this->assertEquals(Zend_Locale_Format::toInteger(-1234567, $options), '-1.234.567', "string -1.234.567 expected");
$this->assertEquals(Zend_Locale_Format::toInteger(1234567, $options), '1.234.567', "string 1.234.567 expected");
$this->assertEquals(Zend_Locale_Format::toInteger(0.1234567, $options), '0', "string 0 expected");
$this->assertEquals(Zend_Locale_Format::toInteger(-1234567.12345, $options), '-1.234.567', "string -1.234.567 expected");
$this->assertEquals(Zend_Locale_Format::toInteger(1234567.12345, $options), '1.234.567', "value 1.234.567 expected");
$this->assertEquals(Zend_Locale_Format::toInteger(1234567.12345, array('locale' => 'ar_QA')), '1234567', "value 1234567 expected");
$this->assertEquals(Zend_Locale_Format::toInteger(-1234567.12345, array('locale' => 'ar_QA')), '1234567-', "value 1234567- expected");
$this->assertEquals(Zend_Locale_Format::toInteger(1234567.12345, array('locale' => 'dz_BT')), '12,34,567', "value 12,34,567 expected");
$this->assertEquals(Zend_Locale_Format::toInteger(-1234567.12345, array('locale' => 'mk_MK')), '-(1.234.567)', "value -(1.234.567) expected");
}
示例7: testIntegerRegionWithTwoSeperatedNegative
/**
* test with two seperation language locale
* expected string
*/
public function testIntegerRegionWithTwoSeperatedNegative()
{
$value = Zend_Locale_Format::toInteger(-1234567.12345, 'mk_MK');
$this->assertEquals($value, '-(1.234.567)', "value -(1.234.567) expected");
}
示例8: numberFormat
function numberFormat($number, $integer = false)
{
if ($integer) {
return Zend_Locale_Format::toInteger($number, array('locale' => $GLOBALS['registry']->currentLang));
}
return Zend_Locale_Format::toNumber($number, array('precision' => NUMBER_FORMAT_PRECISION, 'locale' => $GLOBALS['registry']->currentLang));
}