Skip to content

Commit 7018e84

Browse files
neilcrookespimlie
authored andcommitted
fix: unit format() shouldnt ignore $addSymbol (#9)
* Ensuring unit format doesn't ignore $addSymbol * Removing trailing whitespace
1 parent 9dc7fc1 commit 7018e84

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/Unit.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,17 +434,20 @@ public function substract()
434434
*/
435435
public function format($precision = 3, $addSymbol = true)
436436
{
437-
$symbol = $this->getSymbol();
437+
$format = '%02.' . $precision . 'f';
438438

439-
if (!empty($symbol)) {
440-
$format = '%02.' . $precision . 'f %s';
439+
if (!$addSymbol) {
440+
return sprintf($format, $this->getValue());
441+
}
441442

442-
return sprintf($format, $this->getValue(), $symbol);
443-
} else {
444-
$format = '%02.' . $precision . 'f';
443+
$symbol = $this->getSymbol();
445444

445+
if (empty($symbol)) {
446446
return sprintf($format, $this->getValue());
447447
}
448+
449+
$format .= ' %s';
450+
return sprintf($format, $this->getValue(), $symbol);
448451
}
449452

450453
/**

0 commit comments

Comments
 (0)