---
title: float_int
description: Convert an XFL floating point into an integer (floor)
---
import { Tabs, TabItem, LinkButton, Aside } from '@astrojs/starlight/components';

### Concepts

<LinkButton href="/docs/hooks/concepts/floating-point-numbers-xfl">Floating Point Numbers (XFL)</LinkButton>

### Behaviour

<Tabs>
<TabItem label="C">
* Left shift (multiply by 10) the XFL by the number of specified decimal places
* Convert the resulting XFL to an integer, discarding any remainder
* Return the integer
</TabItem>

<TabItem label="JavaScript">
* Converts a float representation to an integer with specified decimal places.
* An error code or the resulting integer as a number.
</TabItem>
</Tabs>

### Definition

<Tabs>
<TabItem label="C">
```c
int64_t float_int (
    int64_t float1,
    uint32_t decimal_places,
    uint32_t absolute
);
```
</TabItem>

<TabItem label="JavaScript">
```javascript
function float_int(
    f1: bigint,
    decimal_places: number,
    abs: number
  ): ErrorCode | number
```
</TabItem>
</Tabs>



### Example

<Tabs>
<TabItem label="C">
```c
int64_t drops =
    float_int(xahbalance, 6, 0);
```
</TabItem>

<TabItem label="JavaScript">
```javascript
const drops =
    float_int(xahbalance, 6, 0);
```
</TabItem>
</Tabs>



### Parameters

<Tabs>
<TabItem label="C">
| Name            | Type      | Description                                                                                              |
| --------------- | --------- | -------------------------------------------------------------------------------------------------------- |
| float1          | int64_t  | An XFL floating point enclosing number representing the first operand to the addition                    |
| decimal_places | uint32_t | The number of places to shift the decimal to the right before computing the floor of the floating point. |
| absolute        | uint32_t | If `1` also take the absolute of the value before returning it.                                          |

<Aside type="tip">
Negative return values are reserved for error codes. Therefore if you need to execute this function against a negative XFL you should use `absolute = 1`
</Aside>
</TabItem>

<TabItem label="JavaScript">


| Name            | Type   | Description                                   |
| --------------- | ------ | --------------------------------------------- |
| f1              | bigint | The float to convert                          |
| decimal_places | number | The number of decimal places to consider.     |
| abs             | number | Indicates whether to take the absolute value. |
</TabItem>
</Tabs>



### Return Code

<Tabs>
<TabItem label="C">
| Type     | Description                                                                                                                                                                                                                                                                                                                                                                                                       |
| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| int64_t | <p>The computed positive integer<br /><br />If negative, an error:<br /><code>INVALID_FLOAT</code><br />- one of the supplied parameters was not a valid XFL enclosing number<br /><br /><code>INVALID_ARGUMENT</code><br />- attempted to specify more than 15 decimal places.<br /><br /><code>CANT_RETURN_NEGATIVE</code><br />- attempted to return a negative integer but this is not allowed, use <code>absolute = 1</code></p> |
</TabItem>

<TabItem label="JavaScript">


| Type                | Description                                                 |
| ------------------- | ----------------------------------------------------------- |
| number or ErrorCode | Returns an error code or the resulting integer as a number. |
</TabItem>
</Tabs>

