function test_number_with_precision() { $this->assertEqual("111.23", number_with_precision(111.2345)); $this->assertEqual("111.23", number_with_precision(111.2345, array('precision' => 2))); $this->assertEqual("13.00000", number_with_precision(13, array('precision' => 5))); $this->assertEqual("389", number_with_precision(389.32314, array('precision' => 0))); $this->assertEqual("110", number_with_precision(111.2345, array('significant' => true))); $this->assertEqual("100", number_with_precision(111.2345, array('precision' => 1, 'significant' => true))); $this->assertEqual("13.000", number_with_precision(13, array('precision' => 5, 'significant' => true))); $this->assertEqual("13", number_with_precision(13, array('precision' => 5, 'significant' => true, 'strip_insignificant_zeros' => true))); $this->assertEqual("389.3", number_with_precision(389.32314, array('precision' => 4, 'significant' => true))); $this->assertEqual("1.111,23", number_with_precision(1111.2345, array('precision' => 2, 'separator' => ',', 'delimiter' => '.'))); }
/** * Translates numbers to percantage * * @todo * Loss of doc */ public function number_to_percentage($number, $options = array()) { if (empty($number)) { return; } $options = array_merge(self::$DEFAULT_CURRENCY_VALUES, $options); try { $value = number_with_precision($number, array_merge($options, array('raise' => true))); return "{$value}%"; } catch (Exception $e) { if (array_key_exists('raise', $options) && $options['raise'] == true) { throw $e; } else { return "{$number}%"; } } }
public function testNumberWithPrecision() { $this->assertEqual('123.457', number_with_precision('123.456789')); $this->assertEqual('123.46', number_with_precision('123.456789', 2)); $this->assertEqual('123', number_with_precision('123.456789', 0)); }