# How to convert confd\_decimal64 to double?

**URL:** <https://dmap-community.ductus.global/t/how-to-convert-confd-decimal64-to-double/3758>\
**Category:** Core Engine and APIs\
**Created:** [July 25, 2021, 4:31pm UTC](https://dmap-community.ductus.global/t/how-to-convert-confd-decimal64-to-double/3758 "2021-07-25T16:31:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Confduser](https://avatars.discourse-cdn.com/v4/letter/c/aca169/32.png) [@Confduser](https://dmap-community.ductus.global/u/Confduser)\
**Post date:** [July 25, 2021, 4:31pm UTC](https://dmap-community.ductus.global/t/how-to-convert-confd-decimal64-to-double/3758/1 "2021-07-25T16:31:36Z")

</div>

Hi,

I am trying to read few statistics through MAAPI and write it to a file.  
But there are few confd defined data types like confd\_decimal64.

I am trying to fetch the data from confd in the following way.

```
struct confd_decimal64 d64;
if (maapi_get_decimal64_elem(sock, th, &d64, "/interface/stat/average") == CONFD_OK)`

```

Is there a function to convert confd\_decimal64 to double?

Also is there a way to convert the enum to string?

```
int32_t state;
maapi_get_enum_value_elem(sock, th, &state, "/interface/stat/state");

```

When the above stats are polled through cli, I am able to see them giving processed output.

```
#show interface
stat average 3572384792.74
stat state up

```

Is there a confd API which can be used for my case as well?

Thanks

---

<div class="post-metadata">

**Author:** ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)\
**Post date:** [July 25, 2021, 7:57pm UTC](https://dmap-community.ductus.global/t/how-to-convert-confd-decimal64-to-double/3758/2 "2021-07-25T19:57:39Z")

</div>

You can use the confd\_cmd tool to read values using maapi. For example:

```auto
confd_cmd -dd -c 'maapi_get /interface/stat/average'

```

The confd\_cmd tool source code is available at `$CONFD_DIR/src/confd/tools/confd_cmd.c`  
So if you want to write your own program that does the same thing, you can reuse the “maapi\_get” implementation that use maapi\_get\_elem() and confd\_val2str() to get a string representation of any value:

```auto
static void do_maapi_get(char *argv[]) /* <key> */
{
    confd_value_t val;

    OK(maapi_get_elem(ms, mtid, &val, argv[0]));
    print_value(&val, NULL, argv[0], "\n");
    confd_free_value(&val);
}

static void print_value(confd_value_t *valp,
                        struct confd_cs_node *start, char *path, char *eol)
{
    char tmpbuf[BUFSIZ];
    struct confd_cs_node *node = NULL;

    /* Don't call with start NULL and path "", gives ugly error */
    if (start != NULL || path != NULL) {
        node = confd_cs_node_cd(start, path ? path : "");
    }

    if ((node == NULL) ||
        (confd_val2str(node->info.type, valp, tmpbuf, BUFSIZ) == CONFD_ERR)) {
        confd_pp_value(tmpbuf, BUFSIZ, valp);
    }
    printf("%s%s", tmpbuf, eol);
}

```
