HTMLPurifier_UnitConverter::getSigFigs PHP Method

getSigFigs() public method

Returns the number of significant figures in a string number.
public getSigFigs ( string $n ) : integer
$n string Decimal number
return integer number of sigfigs
    public function getSigFigs($n)
    {
        $n = ltrim($n, '0+-');
        $dp = strpos($n, '.');
        // decimal position
        if ($dp === false) {
            $sigfigs = strlen(rtrim($n, '0'));
        } else {
            $sigfigs = strlen(ltrim($n, '0.'));
            // eliminate extra decimal character
            if ($dp !== 0) {
                $sigfigs--;
            }
        }
        return $sigfigs;
    }

Usage Example

Esempio n. 1
0
 protected function assertSigFig($n, $sigfigs)
 {
     $converter = new HTMLPurifier_UnitConverter();
     $result = $converter->getSigFigs($n);
     $this->assertIdentical($result, $sigfigs);
 }