本文整理汇总了PHP中Zend_Locale_Math类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Locale_Math类的具体用法?PHP Zend_Locale_Math怎么用?PHP Zend_Locale_Math使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Locale_Math类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
/**
* Iterate over the order items and calculate the gst
* for each depending on StreakGSTModule.config.currency_percentages()
*
* @param Order $order
* @param null $value
* @throws ValidationException
* @throws null
*/
public function add($order, $value = null)
{
$gst = new Price();
$gst->setCurrency(ShopConfig::current_shop_config()->BaseCurrency);
$descriptions = array();
/** @var Price|null $calculated */
$calculated = null;
/** @var Item $item */
foreach ($order->Items() as $item) {
if ($price = $item->Price()) {
$currency = $price->getCurrency();
if ($rate = self::rate_for_currency($currency)) {
if (!$calculated) {
$calculated = new Price();
}
$percentage = Zend_Locale_Math::Div($rate, 100.0, 10);
$taxed = Zend_Locale_Math::Mul($price, $percentage, 10);
$temp = Zend_Locale_Math::Add($calculated, $taxed, 10);
$calculated->setAmount($temp);
$descriptions[$currency] = static::description($currency);
}
}
}
if ($calculated) {
$mod = new StreakGST_Modification();
$mod->OrderID = $order->ID;
$mod->Price = 0;
$mod->Description = implode("<br/>\n", $descriptions);
$mod->GST = $calculated->getAmount();
$mod->Value = $calculated->getAmount();
$mod->write();
}
}
示例2: provideLeastAmount
/**
* Returns the least of the passed in price and the price with this discount applied, or null
* if this discounted price is larger than the existing one. This can then be used in extension
* call to find the least discounted price.
*
* @param Price $amount
* @return Price|null
*/
public function provideLeastAmount(Price $amount)
{
/** @var StreakDiscountType $discountType */
if (($discountType = $this->owner->StreakDiscountType()) && $discountType->exists()) {
$discounted = $discountType->discountedAmount($amount);
$res = Zend_Locale_Math::Comp($amount->getAmount(), $discounted->getAmount());
if ($res) {
return $discounted;
}
}
return null;
}
示例3: provideLeastAmount
/**
* Returns the least of the passed in price and the price with this discount applied, or null
* if this discounted price is larger than the existing one. This can then be used in extension
* call to find the least discounted price.
*
* @param Price $amount
* @param number $discountAmount
* @return bool
*/
public function provideLeastAmount(Price $amount, $discountAmount)
{
if (!$discountAmount) {
return false;
}
$discounted = self::calc_discounted_amount($amount, $discountAmount);
$res = Zend_Locale_Math::Comp($amount->getAmount(), $discounted->getAmount());
if ($res) {
return $discounted;
}
return null;
}
示例4: discountedAmount
/**
* Returns amount reduced by $this->Measure.
*
* @param Price|number $amount
* @param $discount
* @return Price
*/
public function discountedAmount($forAmount)
{
if ($this->owner->UsePriceColumn) {
$price = new Price();
$price->setCurrency(ShopConfig::current_shop_config()->BaseCurrency);
if ($forAmount instanceof Money) {
$price->setAmount($forAmount->getAmount());
} else {
$price->setAmount($forAmount);
}
$price->setAmount(Zend_Locale_Math::Sub($price->getAmount(), $this->owner->Measure, 10));
return $price;
}
return null;
}
示例5: discountedAmount
/**
* Returns the amount minus percentage from Measure.
*
* @param Price $forAmount
* @return Price
*/
public function discountedAmount($forAmount)
{
if ($this->owner->UsePercentageColumn) {
$price = new Price();
if ($forAmount instanceof Money) {
$price->setAmount($forAmount->getAmount());
$price->setCurrency($forAmount->getCurrency());
} else {
$price->setAmount($forAmount);
$price->setCurrency(ShopConfig::current_shop_config()->BaseCurrency);
}
// only recalculate if there is a percentage
if ($this->owner->Measure != 0) {
$original = $price->getAmount();
$percentage = Zend_Locale_Math::Div($this->owner->Measure, self::OneHundred, 10);
$difference = Zend_Locale_Math::Mul($original, $percentage, 10);
$price->setAmount(Zend_Locale_Math::Sub($original, $difference, 10));
}
return $price;
}
return null;
}
示例6: add
/**
* @param Order $order
* @param null $value
* @throws ValidationException
* @throws null
*/
public function add($order, $value = null)
{
if ($order->ShippingRegionCode) {
if ($orderRegion = Region_Shipping::get()->filter('Code', $order->ShippingRegionCode)->first()) {
$shippingCost = 0.0;
/** @var Item $item */
foreach ($order->Items() as $item) {
$productRegion = $item->Product()->Shippables()->filter('RegionID', $orderRegion->ID)->first();
if ($productRegion) {
$shippingCost = Zend_Locale_Math::Add($shippingCost, Zend_Locale_Math::Mul($productRegion->Price, $item->Quantity));
}
}
//Generate the Modification now that we have picked the correct rate
$mod = new StreakRegionalShipping_Modification();
$mod->OrderID = $order->ID;
$mod->RegionID = $orderRegion->ID;
$mod->Price = $shippingCost;
$mod->Description = "Shipping to {$orderRegion->Title}";
$mod->Value = $shippingCost;
$mod->write();
}
}
}
示例7: setType
/**
* Set a new type, and convert the value
*
* @param string $type New type to set
* @throws Zend_Measure_Exception
* @return Zend_Measure_Abstract
*/
public function setType($type)
{
if (empty($this->_units[$type])) {
require_once 'Zend/Measure/Exception.php';
throw new Zend_Measure_Exception("Type ({$type}) is unknown");
}
if (empty($this->_type)) {
$this->_type = $type;
} else {
// Convert to standard value
$value = $this->_value;
if (is_array($this->_units[$this->getType()][0])) {
foreach ($this->_units[$this->getType()][0] as $key => $found) {
switch ($key) {
case "/":
if ($found != 0) {
$value = call_user_func(Zend_Locale_Math::$div, $value, $found, 25);
}
break;
case "+":
$value = call_user_func(Zend_Locale_Math::$add, $value, $found, 25);
break;
case "-":
$value = call_user_func(Zend_Locale_Math::$sub, $value, $found, 25);
break;
default:
$value = call_user_func(Zend_Locale_Math::$mul, $value, $found, 25);
break;
}
}
} else {
$value = call_user_func(Zend_Locale_Math::$mul, $value, $this->_units[$this->getType()][0], 25);
}
// Convert to expected value
if (is_array($this->_units[$type][0])) {
foreach (array_reverse($this->_units[$type][0]) as $key => $found) {
switch ($key) {
case "/":
$value = call_user_func(Zend_Locale_Math::$mul, $value, $found, 25);
break;
case "+":
$value = call_user_func(Zend_Locale_Math::$sub, $value, $found, 25);
break;
case "-":
$value = call_user_func(Zend_Locale_Math::$add, $value, $found, 25);
break;
default:
if ($found != 0) {
$value = call_user_func(Zend_Locale_Math::$div, $value, $found, 25);
}
break;
}
}
} else {
$value = call_user_func(Zend_Locale_Math::$div, $value, $this->_units[$type][0], 25);
}
$slength = strlen($value);
$length = 0;
for ($i = 1; $i <= $slength; ++$i) {
if ($value[$slength - $i] != '0') {
$length = 26 - $i;
break;
}
}
$this->_value = Zend_Locale_Math::round($value, $length);
$this->_type = $type;
}
return $this;
}
示例8: _round
/**
* Round $number with set $precision
*
* @param float $number Number to round
* @param integer $precision Precision
*/
protected function _round($number, $precision)
{
return Zend_Locale_Math::round($number, $precision);
}
示例9: testNegativeRounding
public function testNegativeRounding()
{
$this->assertEquals('-3', Zend_Locale_Math::round('-3.4'));
$this->assertEquals(round(-3.4), Zend_Locale_Math::round('-3.4'));
$this->assertEquals('-4', Zend_Locale_Math::round('-3.5'));
$this->assertEquals(round(-3.5), Zend_Locale_Math::round('-3.5'));
$this->assertEquals('-4', Zend_Locale_Math::round('-3.6'));
$this->assertEquals(round(-3.6), Zend_Locale_Math::round('-3.6'));
$this->assertEquals('-4', Zend_Locale_Math::round('-3.6', 0));
$this->assertEquals(round(-3.6, 0), Zend_Locale_Math::round('-3.6', 0));
$this->assertEquals('-1.96', Zend_Locale_Math::round('-1.95583', 2), '', 0.02);
$this->assertEquals(round(-1.95583, 2), Zend_Locale_Math::round('-1.95583', 2), '', 0.02);
$this->assertEquals(-1242000, Zend_Locale_Math::round('-1241757', -3), '', 250);
$this->assertEquals(round(-1241757, -3), Zend_Locale_Math::round('-1241757', -3), '', 250);
$this->assertEquals(-5.05, Zend_Locale_Math::round('-5.045', 2), '', 0.02);
$this->assertEquals(round(-5.045, 2), Zend_Locale_Math::round('-5.045', 2), '', 0.02);
$this->assertEquals(-5.06, Zend_Locale_Math::round('-5.055', 2), '', 0.02);
$this->assertEquals(round(-5.055, 2), Zend_Locale_Math::round('-5.055', 2), '', 0.02);
}
示例10: set_include_path
set_include_path(get_include_path() . PATH_SEPARATOR . './library');
// setup Zend autloading, this requires that the library is available via the include_path
require 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
// define float value that will differ between rounding and cutoff
$floatvalue = 1298.85525;
$precision = 2;
$testLocale = 'en_GB';
// setup a fixed locale to get around differeing output formats regarding . and ,
$locale = new Zend_Locale();
$locale->setLocale('en_GB');
Zend_Registry::set('Zend_Locale', $locale);
// what is produced by php round function
// expected result is 1298.86
echo round($floatvalue, $precision);
echo "\n";
// what is produce by Zend_Locale_Math
// expected result is 1298.86
echo Zend_Locale_Math::round($floatvalue, $precision);
echo "\n";
// what is produced by Zend_Locale_Math without specifiying an explicit format
// expected result is 1,298.86
// this will return 1,298.85 instead!
echo Zend_Locale_Format::toNumber($floatvalue, array('precision' => $precision, 'locale' => $locale));
echo "\n";
// what is produced by Zend_Locale_Math with specifiying an explicit format
// expected result is 1,298.86
$format = Zend_Locale_Data::getContent((string) $locale, 'decimalnumber');
echo Zend_Locale_Format::toNumber($floatvalue, array('precision' => $precision, 'locale' => $locale, 'number_format' => $format));
echo "\n";
示例11: toNumber
/**
* Returns a locale formatted number depending on the given options.
* The seperation and fraction sign is used from the set locale.
* ##0.# -> 12345.12345 -> 12345.12345
* ##0.00 -> 12345.12345 -> 12345.12
* ##,##0.00 -> 12345.12345 -> 12,345.12
*
* @param string $input Localized number string
* @param array $options Options: number_format, locale, precision. See {@link setOptions()} for details.
* @return string locale formatted number
*/
public static function toNumber($value, array $options = array())
{
// load class within method for speed
require_once 'Zend/Locale/Math.php';
$value = Zend_Locale_Math::normalize($value);
$options = array_merge(self::$_Options, self::checkOptions($options));
if ($options['locale'] instanceof Zend_Locale) {
$options['locale'] = $options['locale']->toString();
}
// Get correct signs for this locale
$symbols = Zend_Locale_Data::getList($options['locale'], 'symbols');
iconv_set_encoding('internal_encoding', 'UTF-8');
// Get format
$format = $options['number_format'];
if ($format === null) {
$format = Zend_Locale_Data::getContent($options['locale'], 'decimalnumber');
if (iconv_strpos($format, ';') !== false) {
if (call_user_func(Zend_Locale_Math::$comp, $value, 0) < 0) {
$format = iconv_substr($format, iconv_strpos($format, ';') + 1);
} else {
$format = iconv_substr($format, 0, iconv_strpos($format, ';'));
}
}
} else {
// seperate negative format pattern when available
if (iconv_strpos($format, ';') !== false) {
if (call_user_func(Zend_Locale_Math::$comp, $value, 0) < 0) {
$format = iconv_substr($format, iconv_strpos($format, ';') + 1);
} else {
$format = iconv_substr($format, 0, iconv_strpos($format, ';'));
}
}
if (strpos($format, '.')) {
if (is_numeric($options['precision'])) {
$value = Zend_Locale_Math::round($value, $options['precision']);
} else {
if (substr($format, strpos($format, '.') + 1, 3) == '###') {
$options['precision'] = null;
} else {
$options['precision'] = strlen(substr($format, strpos($format, '.') + 1,
strrpos($format, '0') - strpos($format, '.')));
$format = substr($format, 0, strpos($format, '.') + 1) . '###'
. substr($format, strrpos($format, '0') + 1);
}
}
} else {
$value = Zend_Locale_Math::round($value, 0);
$options['precision'] = 0;
}
$value = Zend_Locale_Math::normalize($value);
}
// get number parts
if (strlen($value) != strlen(Zend_Locale_Math::round($value, 0))) {
if ($options['precision'] === null) {
$precstr = iconv_substr($value, strlen(Zend_Locale_Math::round($value, 0)) + 1);
} else {
$precstr = iconv_substr($value, strlen(Zend_Locale_Math::round($value, 0)) + 1, $options['precision']);
if (iconv_strlen($precstr) < $options['precision']) {
$precstr = $precstr . str_pad("0", ($options['precision'] - iconv_strlen($precstr)), "0");
}
}
} else {
if ($options['precision'] > 0) {
$precstr = str_pad("0", ($options['precision']), "0");
}
}
if ($options['precision'] === null) {
if (isset($precstr)) {
$options['precision'] = iconv_strlen($precstr);
} else {
$options['precision'] = 0;
}
}
// get fraction and format lengths
if (strpos($value, '.') !== false) {
$number = substr((string) $value, 0, strpos($value, '.'));
} else {
$number = $value;
}
$prec = call_user_func(Zend_Locale_Math::$sub, $value, $number, $options['precision']);
if (iconv_strpos($prec, '-') !== false) {
//.........这里部分代码省略.........
示例12: setOrderSubtotals
/**
* Calculate and set order MercadoPago specific subtotals based on data values
*
* @param $data
* @param $order
*/
public function setOrderSubtotals($data, $order)
{
if (isset($data['total_paid_amount'])) {
$balance = $this->_getMultiCardValue($data, 'total_paid_amount');
} else {
$balance = $data['transaction_details']['total_paid_amount'];
}
if (isset($data['shipping_cost'])) {
$shippingCost = $this->_getMultiCardValue($data, 'shipping_cost');
$order->setBaseShippingAmount($shippingCost);
$order->setShippingAmount($shippingCost);
} else {
$shippingCost = 0;
}
$order->setGrandTotal($balance);
$order->setBaseGrandTotal($balance);
if ($shippingCost > 0) {
$order->setBaseShippingAmount($shippingCost);
$order->setShippingAmount($shippingCost);
}
$couponAmount = $this->_getMultiCardValue($data, 'coupon_amount');
$transactionAmount = $this->_getMultiCardValue($data, 'transaction_amount');
if ($couponAmount) {
$order->setDiscountCouponAmount($couponAmount * -1);
$order->setBaseDiscountCouponAmount($couponAmount * -1);
$balance = $balance - ($transactionAmount - $couponAmount + $shippingCost);
} else {
$balance = $balance - $transactionAmount - $shippingCost;
}
if (\Zend_Locale_Math::round($balance, 4) > 0) {
$order->setFinanceCostAmount($balance);
$order->setBaseFinanceCostAmount($balance);
}
$order->save();
}
示例13: getAmount
public function getAmount()
{
return Zend_Locale_Math::round($this->amount, 2);
}
示例14: round
/**
* Unified round() implementation for the Datatrans extension
*
* @param mixed $value String, Integer or Float
* @return float
*/
public function round($value)
{
return Zend_Locale_Math::round($value, 2);
}
示例15: setType
/**
* Set a new type, and convert the value
*
* @param string $type New type to set
* @throws Zend_Measure_Exception
*/
public function setType($type)
{
if (empty($this->_units[$type])) {
require_once 'Zend/Measure/Exception.php';
throw new Zend_Measure_Exception("Type ({$type}) is unknown");
}
if (empty($this->_type)) {
$this->_type = $type;
} else {
// Convert to standard value
$value = $this->_value;
$prec = 0;
if (strpos($this->_value, '.') !== false) {
$prec = strlen(substr($this->_value, strpos($this->_value, '.') + 1));
}
if (is_array($this->_units[$this->getType()][0])) {
foreach ($this->_units[$this->getType()][0] as $key => $found) {
switch ($key) {
case "/":
if ($found != 0) {
$value = @call_user_func(Zend_Locale_Math::$div, $value, $found, 25);
}
break;
case "+":
$value = call_user_func(Zend_Locale_Math::$add, $value, $found, 25);
break;
case "-":
$value = call_user_func(Zend_Locale_Math::$sub, $value, $found, 25);
break;
default:
$value = call_user_func(Zend_Locale_Math::$mul, $value, $found, 25);
break;
}
}
} else {
$value = call_user_func(Zend_Locale_Math::$mul, $value, $this->_units[$this->getType()][0], 25);
}
// Convert to expected value
if (is_array($this->_units[$type][0])) {
foreach (array_reverse($this->_units[$type][0]) as $key => $found) {
switch ($key) {
case "/":
$value = call_user_func(Zend_Locale_Math::$mul, $value, $found, 25);
break;
case "+":
$value = call_user_func(Zend_Locale_Math::$sub, $value, $found, 25);
break;
case "-":
$value = call_user_func(Zend_Locale_Math::$add, $value, $found, 25);
break;
default:
if ($found != 0) {
$value = @call_user_func(Zend_Locale_Math::$div, $value, $found, 25);
}
break;
}
}
} else {
$value = @call_user_func(Zend_Locale_Math::$div, $value, $this->_units[$type][0], 25);
}
$this->_value = Zend_Locale_Math::round($value, $prec);
$this->_type = $type;
}
return $this;
}