当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Locale_Math_PhpMath类代码示例

本文整理汇总了PHP中Zend_Locale_Math_PhpMath的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Locale_Math_PhpMath类的具体用法?PHP Zend_Locale_Math_PhpMath怎么用?PHP Zend_Locale_Math_PhpMath使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Zend_Locale_Math_PhpMath类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: round

 /**
  * Surprisingly, the results of this implementation of round()
  * prove better than the native PHP round(). For example, try:
  *   round(639.795, 2);
  *   round(267.835, 2);
  *   round(0.302515, 5);
  *   round(0.36665, 4);
  * then try:
  *   Zend_Locale_Math::round('639.795', 2);
  */
 public static function round($op1, $precision = 0)
 {
     if (self::$_bcmathDisabled) {
         $op1 = round($op1, $precision);
         if (strpos((string) $op1, 'E') === false) {
             return self::normalize(round($op1, $precision));
         }
     }
     if (strpos($op1, 'E') !== false) {
         $op1 = self::floatalize($op1);
     }
     $op1 = trim(self::normalize($op1));
     $length = strlen($op1);
     if (($decPos = strpos($op1, '.')) === false) {
         $op1 .= '.0';
         $decPos = $length;
         $length += 2;
     }
     if ($precision < 0 && abs($precision) > $decPos) {
         return '0';
     }
     $digitsBeforeDot = $length - ($decPos + 1);
     if ($precision >= $length - ($decPos + 1)) {
         return $op1;
     }
     if ($precision === 0) {
         $triggerPos = 1;
         $roundPos = -1;
     } elseif ($precision > 0) {
         $triggerPos = $precision + 1;
         $roundPos = $precision;
     } else {
         $triggerPos = $precision;
         $roundPos = $precision - 1;
     }
     $triggerDigit = $op1[$triggerPos + $decPos];
     if ($precision < 0) {
         // zero fill digits to the left of the decimal place
         $op1 = substr($op1, 0, $decPos + $precision) . str_pad('', abs($precision), '0');
     }
     if ($triggerDigit >= '5') {
         if ($roundPos + $decPos == -1) {
             return str_pad('1', $decPos + 1, '0');
         }
         $roundUp = str_pad('', $length, '0');
         $roundUp[$decPos] = '.';
         $roundUp[$roundPos + $decPos] = '1';
         if ($op1 > 0) {
             if (self::$_bcmathDisabled) {
                 return Zend_Locale_Math_PhpMath::Add($op1, $roundUp, $precision);
             }
             return self::Add($op1, $roundUp, $precision);
         } else {
             if (self::$_bcmathDisabled) {
                 return Zend_Locale_Math_PhpMath::Sub($op1, $roundUp, $precision);
             }
             return self::Sub($op1, $roundUp, $precision);
         }
     } elseif ($precision >= 0) {
         return substr($op1, 0, $decPos + ($precision ? $precision + 1 : 0));
     }
     return (string) $op1;
 }
开发者ID:netconstructor,项目名称:Centurion,代码行数:73,代码来源:Math.php

示例2: Mod

     * BCMod - fixes a problem of BCMath and exponential numbers
     *
     * @param  string  $op1
     * @param  string  $op2
     * @return string
     */
    public static function Mod($op1, $op2)
    {
        $op1 = self::exponent($op1);
        $op2 = self::exponent($op2);
        return bcmod($op1, $op2);
    }
    /**
     * BCComp - fixes a problem of BCMath and exponential numbers
     *
     * @param  string  $op1
     * @param  string  $op2
     * @param  integer $scale
     * @return string
     */
    public static function Comp($op1, $op2, $scale = null)
    {
        $op1 = self::exponent($op1, $scale);
        $op2 = self::exponent($op2, $scale);
        return bccomp($op1, $op2, $scale);
    }
}
if (defined('TESTS_ZEND_LOCALE_BCMATH_ENABLED') && !TESTS_ZEND_LOCALE_BCMATH_ENABLED || !extension_loaded('bcmath')) {
    require_once 'Zend/Locale/Math/PhpMath.php';
    Zend_Locale_Math_PhpMath::disable();
}
开发者ID:VUW-SIM-FIS,项目名称:emiemi,代码行数:31,代码来源:Math.php

示例3: testScale

 public function testScale()
 {
     Zend_Locale_Math_PhpMath::disable();
     $this->assertTrue(Zend_Locale_Math_PhpMath::Scale(3));
     try {
         $this->assertTrue(Zend_Locale_Math_PhpMath::Scale(10));
         $this->fail("exception expected");
     } catch (Zend_Locale_Math_Exception $e) {
         // success
     }
     $this->assertEquals(1, Zend_Locale_Math_PhpMath::Comp(10.5556, 10.4444));
     $this->assertTrue(Zend_Locale_Math_PhpMath::Scale(0));
     $this->assertEquals(0, Zend_Locale_Math_PhpMath::Comp(10.5556, 10.4444));
 }
开发者ID:ThorstenSuckow,项目名称:conjoon,代码行数:14,代码来源:MathTest.php

示例4: disable

 public static function disable()
 {
     self::$_bcmathDisabled = true;
     self::$add = 'Zend_Locale_Math_Add';
     self::$sub = 'Zend_Locale_Math_Sub';
     self::$pow = 'Zend_Locale_Math_Pow';
     self::$mul = 'Zend_Locale_Math_Mul';
     self::$div = 'Zend_Locale_Math_Div';
     self::$comp = 'Zend_Locale_Math_Comp';
     self::$sqrt = 'Zend_Locale_Math_Sqrt';
     self::$mod = 'Zend_Locale_Math_Mod';
     self::$scale = 'Zend_Locale_Math_Scale';
 }
开发者ID:vojtajina,项目名称:sitellite,代码行数:13,代码来源:PhpMath.php

示例5: Scale

 public static function Scale($scale)
 {
     if ($scale > 9) {
         require_once 'Zend/Locale/Math/Exception.php';
         throw new Zend_Locale_Math_Exception("can not scale to precision {$scale}", $scale, null, null);
     }
     self::$defaultScale = $scale;
     self::$defaultPrecision = pow(10, -$scale);
     return true;
 }
开发者ID:Simarpreet05,项目名称:joomla,代码行数:10,代码来源:PhpMath.php

示例6: Scale

 public static function Scale($op1)
 {
     if ($op1 > 9) {
         require_once 'Zend/Locale/Math/Exception.php';
         throw new Zend_Locale_Math_Exception("can not scale to precision $op1", $op1, null, null);
     }
     self::$_scale = $op1;
     return true;
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:9,代码来源:PhpMath.php


注:本文中的Zend_Locale_Math_PhpMath类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。