2024-04-25 14:56:13 +03:00
|
|
|
# round
|
|
|
|
|
|
|
|
Rounds a number to a specified precision.
|
|
|
|
|
2024-06-04 11:19:26 +03:00
|
|
|
This function takes a number and an optional precision value, and returns the number rounded
|
2024-04-25 14:56:13 +03:00
|
|
|
to the specified number of decimal places.
|
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
function round(value: number, precision?: number): number;
|
|
|
|
```
|
|
|
|
|
2024-06-04 11:19:26 +03:00
|
|
|
### Parameters
|
2024-04-25 14:56:13 +03:00
|
|
|
|
|
|
|
- `value` (`number`): The number to round.
|
|
|
|
- `precision` (`number`, optional): The number of decimal places to round to. Defaults to 0.
|
|
|
|
|
|
|
|
### Returns
|
|
|
|
|
|
|
|
(`number`): The rounded number.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
const result1 = round(1.2345); // result1 will be 1
|
|
|
|
const result2 = round(1.2345, 2); // result2 will be 1.23
|
|
|
|
const result3 = round(1.2345, 3); // result3 will be 1.235
|
2024-06-04 11:19:26 +03:00
|
|
|
```
|