Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Static Public Member Functions | Static Public Attributes
Zend_Locale_Math Class Reference
Inheritance diagram for Zend_Locale_Math:
Zend_Locale_Math_PhpMath

Static Public Member Functions

static isBcmathDisabled ()
 
static round ($op1, $precision=0)
 
static floatalize ($value)
 
static normalize ($value)
 
static localize ($value)
 
static exponent ($value, $scale=null)
 
static Add ($op1, $op2, $scale=null)
 
static Sub ($op1, $op2, $scale=null)
 
static Pow ($op1, $op2, $scale=null)
 
static Mul ($op1, $op2, $scale=null)
 
static Div ($op1, $op2, $scale=null)
 
static Sqrt ($op1, $scale=null)
 
static Mod ($op1, $op2)
 
static Comp ($op1, $op2, $scale=null)
 

Static Public Attributes

static $_bcmathDisabled = false
 
static $add = array('Zend_Locale_Math', 'Add')
 
static $sub = array('Zend_Locale_Math', 'Sub')
 
static $pow = array('Zend_Locale_Math', 'Pow')
 
static $mul = array('Zend_Locale_Math', 'Mul')
 
static $div = array('Zend_Locale_Math', 'Div')
 
static $comp = array('Zend_Locale_Math', 'Comp')
 
static $sqrt = array('Zend_Locale_Math', 'Sqrt')
 
static $mod = array('Zend_Locale_Math', 'Mod')
 
static $scale = 'bcscale'
 

Detailed Description

Definition at line 35 of file Math.php.

Member Function Documentation

◆ Add()

static Add (   $op1,
  $op2,
  $scale = null 
)
static

BCAdd - fixes a problem of BCMath and exponential numbers

Parameters
string$op1
string$op2
integer$scale
Returns
string

Definition at line 239 of file Math.php.

240  {
241  $op1 = self::exponent($op1, $scale);
242  $op2 = self::exponent($op2, $scale);
243 
244  return bcadd($op1, $op2, $scale);
245  }
static exponent($value, $scale=null)
Definition: Math.php:213
static $scale
Definition: Math.php:48

◆ Comp()

static Comp (   $op1,
  $op2,
  $scale = null 
)
static

BCComp - fixes a problem of BCMath and exponential numbers

Parameters
string$op1
string$op2
integer$scale
Returns
string

Definition at line 342 of file Math.php.

343  {
344  $op1 = self::exponent($op1, $scale);
345  $op2 = self::exponent($op2, $scale);
346  return bccomp($op1, $op2, $scale);
347  }
static exponent($value, $scale=null)
Definition: Math.php:213
static $scale
Definition: Math.php:48

◆ Div()

static Div (   $op1,
  $op2,
  $scale = null 
)
static

BCDiv - fixes a problem of BCMath and exponential numbers

Parameters
string$op1
string$op2
integer$scale
Returns
string

Definition at line 300 of file Math.php.

301  {
302  $op1 = self::exponent($op1, $scale);
303  $op2 = self::exponent($op2, $scale);
304  return bcdiv($op1, $op2, $scale);
305  }
static exponent($value, $scale=null)
Definition: Math.php:213
static $scale
Definition: Math.php:48

◆ exponent()

static exponent (   $value,
  $scale = null 
)
static

Changes exponential numbers to plain string numbers Fixes a problem of BCMath with numbers containing exponents

Parameters
integer$valueValue to erase the exponent
integer$scale(Optional) Scale to use
Returns
string

Definition at line 213 of file Math.php.

214  {
215  if (!extension_loaded('bcmath')) {
216  return $value;
217  }
218 
219  $split = explode('e', $value);
220  if (count($split) == 1) {
221  $split = explode('E', $value);
222  }
223 
224  if (count($split) > 1) {
225  $value = bcmul($split[0], bcpow(10, $split[1], $scale), $scale);
226  }
227 
228  return $value;
229  }
$value
Definition: gender.phtml:16
static $scale
Definition: Math.php:48

◆ floatalize()

static floatalize (   $value)
static

Convert a scientific notation to float Additionally fixed a problem with PHP <= 5.2.x with big integers

Parameters
string$value

Definition at line 144 of file Math.php.

145  {
146  $value = strtoupper($value);
147  if (strpos($value, 'E') === false) {
148  return $value;
149  }
150 
151  $number = substr($value, 0, strpos($value, 'E'));
152  if (strpos($number, '.') !== false) {
153  $post = strlen(substr($number, strpos($number, '.') + 1));
154  $mantis = substr($value, strpos($value, 'E') + 1);
155  if ($mantis < 0) {
156  $post += abs((int) $mantis);
157  }
158 
159  $value = number_format($value, $post, '.', '');
160  } else {
161  $value = number_format($value, 0, '.', '');
162  }
163 
164  return $value;
165  }
$number
Definition: details.phtml:22
$value
Definition: gender.phtml:16

◆ isBcmathDisabled()

static isBcmathDisabled ( )
static

Definition at line 50 of file Math.php.

51  {
53  }
static $_bcmathDisabled
Definition: Math.php:38

◆ localize()

static localize (   $value)
static

Localizes an input from standard english notation Fixes a problem of BCMath with setLocale which is PHP related

Parameters
integer$valueValue to normalize
Returns
string Normalized string without BCMath problems

Definition at line 195 of file Math.php.

196  {
197  $convert = localeconv();
198  $value = str_replace(".", $convert['decimal_point'], (string) $value);
199  if (!empty($convert['negative_sign']) and (strpos($value, "-"))) {
200  $value = str_replace("-", $convert['negative_sign'], $value);
201  }
202  return $value;
203  }
$value
Definition: gender.phtml:16

◆ Mod()

static Mod (   $op1,
  $op2 
)
static

BCMod - fixes a problem of BCMath and exponential numbers

Parameters
string$op1
string$op2
Returns
string

Definition at line 327 of file Math.php.

328  {
329  $op1 = self::exponent($op1);
330  $op2 = self::exponent($op2);
331  return bcmod($op1, $op2);
332  }
static exponent($value, $scale=null)
Definition: Math.php:213

◆ Mul()

static Mul (   $op1,
  $op2,
  $scale = null 
)
static

BCMul - fixes a problem of BCMath and exponential numbers

Parameters
string$op1
string$op2
integer$scale
Returns
string

Definition at line 285 of file Math.php.

286  {
287  $op1 = self::exponent($op1, $scale);
288  $op2 = self::exponent($op2, $scale);
289  return bcmul($op1, $op2, $scale);
290  }
static exponent($value, $scale=null)
Definition: Math.php:213
static $scale
Definition: Math.php:48

◆ normalize()

static normalize (   $value)
static

Normalizes an input to standard english notation Fixes a problem of BCMath with setLocale which is PHP related

Parameters
integer$valueValue to normalize
Returns
string Normalized string without BCMath problems

Definition at line 174 of file Math.php.

175  {
176  $convert = localeconv();
177  $value = str_replace($convert['thousands_sep'], "",(string) $value);
178  $value = str_replace($convert['positive_sign'], "", $value);
179  $value = str_replace($convert['decimal_point'], ".",$value);
180  if (!empty($convert['negative_sign']) and (strpos($value, $convert['negative_sign']))) {
181  $value = str_replace($convert['negative_sign'], "", $value);
182  $value = "-" . $value;
183  }
184 
185  return $value;
186  }
$value
Definition: gender.phtml:16

◆ Pow()

static Pow (   $op1,
  $op2,
  $scale = null 
)
static

BCPow - fixes a problem of BCMath and exponential numbers

Parameters
string$op1
string$op2
integer$scale
Returns
string

Definition at line 270 of file Math.php.

271  {
272  $op1 = self::exponent($op1, $scale);
273  $op2 = self::exponent($op2, $scale);
274  return bcpow($op1, $op2, $scale);
275  }
static exponent($value, $scale=null)
Definition: Math.php:213
static $scale
Definition: Math.php:48

◆ round()

static round (   $op1,
  $precision = 0 
)
static

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);

Definition at line 65 of file Math.php.

66  {
67  if (self::$_bcmathDisabled) {
68  $op1 = round($op1, $precision);
69  if (strpos((string) $op1, 'E') === false) {
70  return self::normalize(round($op1, $precision));
71  }
72  }
73 
74  if (strpos($op1, 'E') !== false) {
75  $op1 = self::floatalize($op1);
76  }
77 
78  $op1 = trim(self::normalize($op1));
79  $length = strlen($op1);
80  if (($decPos = strpos($op1, '.')) === false) {
81  $op1 .= '.0';
82  $decPos = $length;
83  $length += 2;
84  }
85  if ($precision < 0 && abs($precision) > $decPos) {
86  return '0';
87  }
88 
89  $digitsBeforeDot = $length - ($decPos + 1);
90  if ($precision >= ($length - ($decPos + 1))) {
91  return $op1;
92  }
93 
94  if ($precision === 0) {
95  $triggerPos = 1;
96  $roundPos = -1;
97  } elseif ($precision > 0) {
98  $triggerPos = $precision + 1;
99  $roundPos = $precision;
100  } else {
101  $triggerPos = $precision;
102  $roundPos = $precision -1;
103  }
104 
105  $triggerDigit = $op1[$triggerPos + $decPos];
106  if ($precision < 0) {
107  // zero fill digits to the left of the decimal place
108  $op1 = substr($op1, 0, $decPos + $precision) . str_pad('', abs($precision), '0');
109  }
110 
111  if ($triggerDigit >= '5') {
112  if ($roundPos + $decPos == -1) {
113  return str_pad('1', $decPos + 1, '0');
114  }
115 
116  $roundUp = str_pad('', $length, '0');
117  $roundUp[$decPos] = '.';
118  $roundUp[$roundPos + $decPos] = '1';
119 
120  if ($op1 > 0) {
121  if (self::$_bcmathDisabled) {
122  return Zend_Locale_Math_PhpMath::Add($op1, $roundUp, $precision);
123  }
124  return self::Add($op1, $roundUp, $precision);
125  } else {
126  if (self::$_bcmathDisabled) {
127  return Zend_Locale_Math_PhpMath::Sub($op1, $roundUp, $precision);
128  }
129  return self::Sub($op1, $roundUp, $precision);
130  }
131  } elseif ($precision >= 0) {
132  return substr($op1, 0, $decPos + ($precision ? $precision + 1: 0));
133  }
134 
135  return (string) $op1;
136  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
static Sub($op1, $op2, $scale=null)
Definition: PhpMath.php:80
static floatalize($value)
Definition: Math.php:144
static Add($op1, $op2, $scale=null)
Definition: PhpMath.php:57
static Sub($op1, $op2, $scale=null)
Definition: Math.php:255
static normalize($value)
Definition: Math.php:174
static round($op1, $precision=0)
Definition: Math.php:65
static Add($op1, $op2, $scale=null)
Definition: Math.php:239

◆ Sqrt()

static Sqrt (   $op1,
  $scale = null 
)
static

BCSqrt - fixes a problem of BCMath and exponential numbers

Parameters
string$op1
integer$scale
Returns
string

Definition at line 314 of file Math.php.

315  {
316  $op1 = self::exponent($op1, $scale);
317  return bcsqrt($op1, $scale);
318  }
static exponent($value, $scale=null)
Definition: Math.php:213
static $scale
Definition: Math.php:48

◆ Sub()

static Sub (   $op1,
  $op2,
  $scale = null 
)
static

BCSub - fixes a problem of BCMath and exponential numbers

Parameters
string$op1
string$op2
integer$scale
Returns
string

Definition at line 255 of file Math.php.

256  {
257  $op1 = self::exponent($op1, $scale);
258  $op2 = self::exponent($op2, $scale);
259  return bcsub($op1, $op2, $scale);
260  }
static exponent($value, $scale=null)
Definition: Math.php:213
static $scale
Definition: Math.php:48

Field Documentation

◆ $_bcmathDisabled

$_bcmathDisabled = false
static

Definition at line 38 of file Math.php.

◆ $add

$add = array('Zend_Locale_Math', 'Add')
static

Definition at line 40 of file Math.php.

◆ $comp

$comp = array('Zend_Locale_Math', 'Comp')
static

Definition at line 45 of file Math.php.

◆ $div

$div = array('Zend_Locale_Math', 'Div')
static

Definition at line 44 of file Math.php.

◆ $mod

$mod = array('Zend_Locale_Math', 'Mod')
static

Definition at line 47 of file Math.php.

◆ $mul

$mul = array('Zend_Locale_Math', 'Mul')
static

Definition at line 43 of file Math.php.

◆ $pow

$pow = array('Zend_Locale_Math', 'Pow')
static

Definition at line 42 of file Math.php.

◆ $scale

$scale = 'bcscale'
static

Definition at line 48 of file Math.php.

◆ $sqrt

$sqrt = array('Zend_Locale_Math', 'Sqrt')
static

Definition at line 46 of file Math.php.

◆ $sub

$sub = array('Zend_Locale_Math', 'Sub')
static

Definition at line 41 of file Math.php.


The documentation for this class was generated from the following file: