You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-2Lines changed: 23 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,8 +45,7 @@ Increasing the default precision with `setPrecision()` allows the specified numb
45
45
```
46
46
> 512.55 KiB
47
47
48
-
Increasing the precision will increase the maximum digits allowed but the formatter will only display as many as
49
-
needed.
48
+
Increasing the precision will increase the maximum digits allowed, but the formatter will only display as many as needed.
50
49
51
50
```php
52
51
(new ByteFormatter)->setPrecision(2)->format(0x80200);
@@ -67,6 +66,28 @@ The default precision can be overridden by passing the second argument to `forma
67
66
```
68
67
> 512.5498 KiB
69
68
69
+
Significant figures
70
+
-------------------
71
+
72
+
Formatting by the specified number of significant figures by calling `setSignificantFigures()`. This is mutually exclusive with precision scaling such that whichever method is called last will be used.
73
+
74
+
```php
75
+
(new ByteFormatter)->setBase(Base::DECIMAL)->setSignificantFigures(2)->format(123);
76
+
```
77
+
> 120
78
+
79
+
```php
80
+
(new ByteFormatter)->setBase(Base::DECIMAL)->setSignificantFigures(2)->format(1234);
81
+
```
82
+
> 1.2K
83
+
84
+
```php
85
+
(new ByteFormatter)->setBase(Base::DECIMAL)->setSignificantFigures(3)->format(1234);
86
+
```
87
+
> 1.23K
88
+
89
+
This is particularly useful for keeping the display width of formatted numbers predicable.
0 commit comments