File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -34,11 +34,12 @@ public function __construct(UnitDecorator $unitDecorator = null)
3434 ;
3535 }
3636
37- public function format ($ bytes )
37+ public function format ($ bytes, $ precision = null )
3838 {
39+ $ precision = $ precision === null ? $ this ->precision : $ precision ;
3940 $ log = log ($ bytes , $ this ->base );
4041 $ exponent = max (0 , $ log |0 );
41- $ value = round (pow ($ this ->base , $ log - $ exponent ), $ this -> precision );
42+ $ value = round (pow ($ this ->base , $ log - $ exponent ), $ precision );
4243 $ units = $ this ->getUnitDecorator ()->decorate ($ exponent , $ this ->base , $ value );
4344
4445 return trim (sprintf ($ this ->normalizedFormat , $ value , $ units ));
Original file line number Diff line number Diff line change @@ -77,7 +77,11 @@ public function provideDecimalIntegers()
7777 /** @dataProvider providePrecisionIntegers */
7878 public function testPrecision ($ integer , $ formatted )
7979 {
80- $ this ->assertSame ($ formatted , $ this ->formatter ->setPrecision (2 )->format ($ integer ));
80+ $ withArgument = $ this ->formatter ->setPrecision (5 )->format ($ integer , 2 );
81+ $ withMethod = $ this ->formatter ->setPrecision (2 )->format ($ integer );
82+
83+ $ this ->assertSame ($ formatted , $ withMethod );
84+ $ this ->assertSame ($ withMethod , $ withArgument );
8185 }
8286
8387 public function providePrecisionIntegers ()
You can’t perform that action at this time.
0 commit comments