/** * Define o tamanho máximo de casas decimais que o número deve ter * @param float $value * @param array $params Lista de flags */ protected function decimalsize($value, $params) { $size = getValueFromArray($params, Flag::DECIMAL_SIZE); if (getValueFromArray($params, Flag::TRUNCATE, false)) { $value = truncateDecimal($value, $size); } else { $value = round($value, $size); } return $value; }
public function testTruncateDecimal() { $this->assertEquals(1.2, truncateDecimal(1.2341, 1)); $this->assertEquals(1.2, truncateDecimal(1.2741, 1)); $this->assertEquals(1.3, round(1.2741, 1)); $this->assertEquals(1.274, truncateDecimal(1.2741, 3)); $this->assertEquals(1.2741, truncateDecimal(1.2741, 4)); $this->assertEquals(1.2741, truncateDecimal(1.2741, 5)); $this->assertEquals(1.0, truncateDecimal(1.1, 0)); $this->assertEquals(1.0, truncateDecimal(1.121, 0)); $this->assertEquals(1.121, truncateDecimal(1.121, -1)); $this->assertEquals(1.1, truncateDecimal(1.1, 2)); $this->assertEquals(1.1, truncateDecimal(1.1, 7)); }