Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
calc_formula Class Reference

This class abstracts evaluation of spreadsheet formulas. More...

Public Member Functions

 __construct ($formula, $params=false)
 Constructor for spreadsheet formula with optional parameters.
 
 calc_formula ($formula, $params=false)
 Old syntax of class constructor.
 
 evaluate ()
 Evaluate formula.
 
 get_error ()
 Get last error.
 
 set_params ($params)
 Raplace parameters used in existing formula, parameter names must contain only lowercase [a-z] letters, no other characters are allowed!
 

Static Public Member Functions

static localize ($formula)
 Similar to format_float, formats the numbers and list separators according to locale specifics.
 
static unlocalize ($formula)
 Similar to unformat_float, converts floats and lists to PHP standards.
 

Public Attributes

 $_em
 
 $_error = false
 
 $_nfx = false
 

Detailed Description

This class abstracts evaluation of spreadsheet formulas.

See also
evalmath/evalmath.class.php See unit tests in lib/tests/mathslib_test.php for sample usage.
License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

calc_formula::__construct ( $formula,
$params = false )

Constructor for spreadsheet formula with optional parameters.

Parameters
string$formulawith leading =
array$paramsassociative array of parameters used in formula. All parameter names must be lowercase!

Member Function Documentation

◆ calc_formula()

calc_formula::calc_formula ( $formula,
$params = false )

Old syntax of class constructor.

Deprecated in PHP7.

Deprecated
since Moodle 3.1

◆ evaluate()

calc_formula::evaluate ( )

Evaluate formula.

Return values
mixednumber if ok, false if error

◆ get_error()

calc_formula::get_error ( )

Get last error.

TODO: localize the strings from contructor and EvalMath library

Return values
mixedstring with last error description or false if ok

◆ localize()

static calc_formula::localize ( $formula)
static

Similar to format_float, formats the numbers and list separators according to locale specifics.

Parameters
string$formula
Return values
stringlocalised formula

◆ set_params()

calc_formula::set_params ( $params)

Raplace parameters used in existing formula, parameter names must contain only lowercase [a-z] letters, no other characters are allowed!

Parameters
array$paramsassociative array of parameters used in formula

◆ unlocalize()

static calc_formula::unlocalize ( $formula)
static

Similar to unformat_float, converts floats and lists to PHP standards.

Parameters
string$formulalocalised formula
Return values
string

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