---
title: float_sto_set
description: Read a serialized amount into an XFL
---
import { Tabs, TabItem, LinkButton } from '@astrojs/starlight/components';

### Concepts

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

### Behaviour

<Tabs>
<TabItem label="C">
* Read a serialized floating point number.
* If there are more fields/data after the serialized floating pointer number then ignore them.
* Return it as an XFL enclosing number
</TabItem>

<TabItem label="JavaScript">
* Sets the buffer for storing float representations.
* Returns ErrorCode or the result as a number.
</TabItem>
</Tabs>



### Definition

<Tabs>
<TabItem label="C">
```c
int64_t float_sto_set (
    uint32_t read_ptr,
    uint32_t read_len
);
```
</TabItem>

<TabItem label="JavaScript">
```javascript
function float_sto_set(buf: ByteArray | HexString): ErrorCode | number
```
</TabItem>
</Tabs>



### Example

<Tabs>
<TabItem label="C">
```c
int64_t vault_pusd = float_sto_set(vault, 8);
if (vault_pusd < 0)
  rollback("Failed to parse serialized float.", 33, 1);
```


</TabItem>

<TabItem label="JavaScript">
```javascript
const vault_pusd = float_sto_set(vault)
if (typeof vault_pusd === 'string')
  rollback("Failed to parse serialized float.", 1)
```
</TabItem>
</Tabs>



### Parameters

<Tabs>
<TabItem label="C">
| Name      | Type      | Description                                                       |
| --------- | --------- | ----------------------------------------------------------------- |
| read_ptr | uint32_t | Pointer to a buffer contianing the serialized XFL. _May be null._ |
| read_len | uint32_t | The length of the buffer.                                         |


</TabItem>

<TabItem label="JavaScript">
| Name | Type                   | Description        |
| ---- | ---------------------- | ------------------ |
| buf  | ByteArray \| HexString | The buffer to set. |
</TabItem>
</Tabs>



### Return Code

<Tabs>
<TabItem label="C">
| Type     | Description                                                                                                                                                                                                                                                                                      |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| int64_t | <p>The number of bytes written to the output buffer.<br /><br />If negative, an error:<br /><code>NOT_AN_OBJECT</code><br />- the supplied buffer did not contain a valid serialized floating point number<br /><br /><code>OUT_OF_BOUNDS</code><br />- pointers/lengths specified outside of hook memory.</p> |
</TabItem>

<TabItem label="JavaScript">
| Type                | Description                              |
| ------------------- | ---------------------------------------- |
| ErrorCode or number | An error code or the result as a number. |
</TabItem>
</Tabs>

