\HTMLPurifier_UnitConverter

Class for converting between different unit-lengths as specified by CSS.

Summary

Methods
Properties
Constants
__construct()
convert()
getSigFigs()
No public properties found
ENGLISH
METRIC
DIGITAL
No protected methods found
$units
$outputPrecision
$internalPrecision
N/A
add()
mul()
div()
round()
scale()
$bcmath
N/A

Constants

ENGLISH

ENGLISH = 1

DIGITAL

DIGITAL = 3

Properties

$units

$units

Units information array. Units are grouped into measuring systems (English, Metric), and are assigned an integer representing the conversion factor between that unit and the smallest unit in the system. Numeric indexes are actually magical constants that encode conversion data from one system to the next, with a O(n^2) constraint on memory (this is generally not a problem, since the number of measuring systems is small.)

$outputPrecision

$outputPrecision

Minimum bcmath precision for output.

$internalPrecision

$internalPrecision

Bcmath precision for internal calculations.

$bcmath

$bcmath

Whether or not BCMath is available.

Methods

__construct()

__construct(mixed  $output_precision = 4, mixed  $internal_precision = 10, mixed  $force_no_bcmath = false) : mixed

Parameters

mixed $output_precision
mixed $internal_precision
mixed $force_no_bcmath

Returns

mixed —

convert()

convert(\HTMLPurifier_Length  $length, string  $to_unit) : \HTMLPurifier_Length|bool

Converts a length object of one unit into another unit.

Parameters

\HTMLPurifier_Length $length

Instance of HTMLPurifier_Length to convert. You must validate() it before passing it here!

string $to_unit

Unit to convert to.

Returns

\HTMLPurifier_Length|bool —

getSigFigs()

getSigFigs(string  $n) : int

Returns the number of significant figures in a string number.

Parameters

string $n

Decimal number

Returns

int —

number of sigfigs

add()

add(string  $s1, string  $s2, int  $scale) : string

Adds two numbers, using arbitrary precision when available.

Parameters

string $s1
string $s2
int $scale

Returns

string —

mul()

mul(string  $s1, string  $s2, int  $scale) : string

Multiples two numbers, using arbitrary precision when available.

Parameters

string $s1
string $s2
int $scale

Returns

string —

div()

div(string  $s1, string  $s2, int  $scale) : string

Divides two numbers, using arbitrary precision when available.

Parameters

string $s1
string $s2
int $scale

Returns

string —

round()

round(float  $n, int  $sigfigs) : string

Rounds a number according to the number of sigfigs it should have, using arbitrary precision when available.

Parameters

float $n
int $sigfigs

Returns

string —

scale()

scale(float  $r, int  $scale) : string

Scales a float to $scale digits right of decimal point, like BCMath.

Parameters

float $r
int $scale

Returns

string —