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
$new = $measurement->minus(new Duration(2500, 'ms'), scale: 2, RoundingMode::HALF_UP); // Returns a new Duration with 117.5 seconds
879
881
```
880
882
881
-
If you need to perform more complex calculations, you can directly access the `value` property, which is a `BigDecimal` object. You can use `BigDecimal` methods for calculations and then create a new Measurement object using the `with()` or `withValue()` methods. These methods also accept a `Closure` as a parameter, allowing for more flexible calculations.
883
+
If you need to perform more complex calculations, you can directly access the `value` property, which is a `BigDecimal`
884
+
object. You can use `BigDecimal` methods for calculations and then create a new Measurement object using the `with()` or
885
+
`withValue()` methods. These methods also accept a `Closure` as a parameter, allowing for more flexible calculations.
Some Measurements require combining multiple units, referred to as `num` (numerator) and `deno` (denominator), representing the units in the numerator and denominator.
901
+
Some Measurements require combining multiple units, referred to as `num` (numerator) and `deno` (denominator),
902
+
representing the units in the numerator and denominator.
898
903
899
-
For example, Speed requires both distance and time, making it a Compound Measurement composed of `Length` (numerator) and `Duration` (denominator). When expressing the unit of Speed, it will be the unit of `Length` divided by the unit of `Duration`, such as `m/s` or `km/h`.
904
+
For example, Speed requires both distance and time, making it a Compound Measurement composed of `Length` (numerator)
905
+
and `Duration` (denominator). When expressing the unit of Speed, it will be the unit of `Length` divided by the unit of
906
+
`Duration`, such as `m/s` or `km/h`.
900
907
901
908
```php
902
909
$speed = Speed::from('100 km/h'); // 100 kilometers per hour
@@ -912,7 +919,8 @@ Each Compound Measurement has some predefined units, which are commonly used int
912
919
-`mps` (m/s, meters per second)
913
920
-`knots` (knots, nautical miles per hour)
914
921
915
-
These units can be directly used in the `from()` or `convertTo()` methods, making it convenient to create or convert Compound Measurements.
922
+
These units can be directly used in the `from()` or `convertTo()` methods, making it convenient to create or convert
923
+
Compound Measurements.
916
924
917
925
```php
918
926
$speed = Speed::from('100 kph'); // 100 kilometers per hour
@@ -925,11 +933,12 @@ Here is a simple example. To create a custom Measurement, you need to extend the
925
933
There are three required properties to implement:
926
934
`$atomUnit` represents the smallest indivisible unit,
927
935
`$defaultUnit` is the default unit,
928
-
and `$unitExchanges` defines the conversion rates between units.
936
+
and `$unitExchanges` defines the conversion rates between units.
929
937
930
938
Make sure to include at least one base unit with a rate of `1`, as some calculations may fail without it.
931
939
932
-
The `normalizeUnit()` method is optional. It is used to convert input unit strings into supported units and is called during string parsing or unit conversion.
940
+
The `normalizeUnit()` method is optional. It is used to convert input unit strings into supported units and is called
941
+
during string parsing or unit conversion.
933
942
934
943
```php
935
944
class ScreenMeasurement extends AbstractBasicMeasurement
@@ -965,9 +974,11 @@ class ScreenMeasurement extends AbstractBasicMeasurement
965
974
966
975
### Dynamic Measurement
967
976
968
-
You can use `DynamicMeasurement` to create a dynamic Measurement that allows you to set units and exchange rates at runtime.
977
+
You can use `DynamicMeasurement` to create a dynamic Measurement that allows you to set units and exchange rates at
978
+
runtime.
969
979
970
-
Below is an example of a dynamic currency conversion Measurement. This is useful for e-commerce systems where exchange rates and currencies can be configured dynamically.
980
+
Below is an example of a dynamic currency conversion Measurement. This is useful for e-commerce systems where exchange
981
+
rates and currencies can be configured dynamically.
Because there are many area units, the Area class provides the `withOnlyCommonAreas()`method to limit available units, keeping only the most common metric area units:
0 commit comments