Number.to_fixed
Number.to_fixed
Function
Format a number to specified decimal places.
Syntax
number.to_fixed(digits)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| digits | Int | No | 0 | Number of decimal places; negative numbers are treated as 0. |
Return value
| Type | Description |
|---|---|
| String | Returns a string with fixed decimal places. |
Example
num = 3.14159 result = num.to_fixed(2) // Output: 3.14 print result
Notes
- The result is a string, not a number.