---
name: "toFixed"
type: command
status: ok
groups: ["Math", "Strings"]
arma3_since: "1.66"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/toFixed
revid: 369349
updated: 2024-09-03T18:43:03Z
---

# toFixed

*Command · Math, Strings · Arma 3 v1.66*

## Description

Converts a number into a string, keeping the specified number of decimals. If the desired number of decimals is higher than the actual number, nulls are added to create the desired decimal length. This command is almost identical in behaviour to JavaScript [toFixed()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)

The alternative syntax acts as keyword and switches engine's [Number](../topics/Number.md) to [String](../topics/String.md) global conversion into desired format, from the moment it is applied until the end of script.
To reset output back to default at any time, use `toFixed -1` - see [#Example 5](../commands/toFixed.md#example-5).

> [!NOTE]
> Converted number is never presented in scientific notation unlike with other number to string commands. Also Arma's default string conversion limits numbers to 6 [significant figures](https://en.wikipedia.org/wiki/Significant_figures), whereas with this command it is possible to preserve some extra precision - see [#Example 6](../commands/toFixed.md#example-6).

## Syntax

### Syntax 1

```sqf
number toFixed decimals
```

**Parameters:**

- `number`: [Number](../topics/Number.md) - number to convert
- `decimals`: [Number](../topics/Number.md) - number of decimals to display (range 0-20)

**Returns:** [String](../topics/String.md)

### Syntax 2

*since arma3 1.72*

```sqf
toFixed decimals
```

**Parameters:**

- `decimals`: [Number](../topics/Number.md) - number of decimals to display (range 0-20). -1 to reset to default number of decimals

**Returns:** [Nothing](../topics/Nothing.md)

## Examples

### Example 1

```sqf
123 toFixed 2; // "123.00"
```

### Example 2

```sqf
2.34 toFixed 1; // "2.3"
2.35 toFixed 1; // "2.4"
```

### Example 3

Convert position to string preserving position precision:

```sqf
fn_posToString = 
{
    format [
        "[%1,%2,%3]", 
        _this select 0 toFixed 8, 
        _this select 1 toFixed 8, 
        _this select 2 toFixed 8
    ]
};
str getPos player;                    // "[3231.05,171.802,0.00143862]"
getPos player call fn_posToString;    // "[3231.04882813,171.80192566,0.00143862]"
```

### Example 4

Same as **Example 3** only using new alternative syntax:

```sqf
str getPos player; // "[3231.05,171.802,0.00143862]"
toFixed 8;
str getPos player; // "[3231.04882813,171.80192566,0.00143862]"
```

### Example 5

```sqf
systemChat str position player;        // [11580.3,11797.7,0.00146675]
call
{
    toFixed 6;
    systemChat str position player;    // [11580.341797,11797.737305,0.001467]
};
systemChat str position player;        // [11580.341797,11797.737305,0.001467]
toFixed -1;
systemChat str position player;        // [11580.3,11797.7,0.00146675]
```

Ideal to be used when saving data to a database when more precise positioning is required.

### Example 6

```sqf
str (pi/100000);        // "3.14159e-005" - scientific notation
(pi/100000) toFixed 10;    // "0.0000314159" - no scientific notation
str pi;                    // "3.14159" - 6 significant figures (default)
pi toFixed 6;            // "3.141593" - forced to 7 significant figures
pi toFixed 7;            // "3.1415927" - forced to 8 significant figures
```

## See also

[toString](../commands/toString.md) · [toArray](../commands/toArray.md) · [toLower](../commands/toLower.md) · [toUpper](../commands/toUpper.md) · [toLowerANSI](../commands/toLowerANSI.md) · [toUpperANSI](../commands/toUpperANSI.md)

## Community notes

**R3vo** — 2016-09-02

```sqf
parseNumber (3.56346 toFixed 4);        // 0.0026 ms (10000 cycles)
[3.5634,4] call BIS_fnc_cutDecimals;    // 0.0111 ms (10000 cycles)
```

<sub>Source: [BI Community Wiki — toFixed](https://community.bistudio.com/wiki/toFixed) (revision 369349).</sub>
