public function format($format)
    {
        // Sprintf and unit regex
        $pattern = '/(%(?:\d+\$)?[+-]?(?:[ 0]|\'.{1})?-?\d*(?:\.\d+)?[bcdeEufFgGosxX])([ ]*)(.*)/';

        // Check if string has sprintf and unit...
        if (preg_match_all($pattern, $format, $m)) {
            $sprintf = $m[1][0];
            $space   = $m[2][0];
            $units   = $m[3][0];

            $velocity = $this->units($units);

            // Should just display as scientific notation?
            if (sprintf($sprintf, $velocity) == 0 || $velocity > 10e9) {
                // Change sprintf to use e for scientific notation
                $sprintf = preg_replace('/[bcdeEufFgGosxX]/', 'e', $sprintf);
            }

            // Return format
            return sprintf($sprintf, $velocity) . $space . $units;
        }
    }
public function format($format)
    {
        // Sprintf and unit regex
        $pattern = '/(%(?:\d+\$)?[+-]?(?:[ 0]|\'.{1})?-?\d*(?:\.\d+)?[bcdeEufFgGosxX])([ ]*)(.*)/';

        // Check if string has sprintf and unit...
        if (preg_match_all($pattern, $format, $m)) {
            $sprintf = $m[1][0];
            $space   = $m[2][0];
            $units   = $m[3][0];

            $velocity = $this->units($units);

            // Should just display as scientific notation?
            if (sprintf($sprintf, $velocity) == 0 || $velocity > 10e9) {
                // Change sprintf to use e for scientific notation
                $sprintf = preg_replace('/[bcdeEufFgGosxX]/', 'e', $sprintf);
            }

            // Return format
            return sprintf($sprintf, $velocity) . $space . $units;
        }
    }
public function format ( $ format ) { // Sprintf and unit regex $ pattern = '/(%(?:\d+\$)?[+-]?(?:[ 0]|\'.{1})?-?\d*(?:\.\d+)?[bcdeEufFgGosxX])([ ]*)(.*)/' ; // Check if string has sprintf and unit... if ( preg_match_all ( $ pattern , $ format , $ m ) ) { $ sprintf = $ m [ 1 ] [ 0 ] ; $ space = $ m [ 2 ] [ 0 ] ; $ units = $ m [ 3 ] [ 0 ] ; $ velocity = $ this -> units ( $ units ) ; // Should just display as scientific notation? if ( sprintf ( $ sprintf , $ velocity ) == 0 || $ velocity > 10e9 ) { // Change sprintf to use e for scientific notation $ sprintf = preg_replace ( '/[bcdeEufFgGosxX]/' , 'e' , $ sprintf ) ; } // Return format return sprintf ( $ sprintf , $ velocity ) . $ space . $ units ; } }
Formats this instance as a string with the provided format.

@param $format Format, e.g. %1.3f m/s

@return string
Formats this instance as a string with the provided format .