# Jsonata $number(hexstring) not working

**URL:** <https://discourse.nodered.org/t/jsonata-number-hexstring-not-working/77672>\
**Category:** General\
**Created:** [17 April 2023 18:27 UTC](https://discourse.nodered.org/t/jsonata-number-hexstring-not-working/77672 "2023-04-17T18:27:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [17 April 2023 18:27 UTC](https://discourse.nodered.org/t/jsonata-number-hexstring-not-working/77672/1 "2023-04-17T18:27:23Z")

</div>

Hi

According to [Numeric functions · JSONata](https://docs.jsonata.org/numeric-functions) the function `$number("0x12")` should return the parsed number `18` (and not 0x18...)  
However in Node-RED 3.0.2 I get error "Unable to cast value to a number"

Can someone confirm ?  
I can't seem to find any existing issue on [jsonata-js/jsonata](https://github.com/jsonata-js/jsonata) however I see that Node-RED use v1.8.6 while the latest release available is 2.0.2  
Is it possible to easily update Jsonata on a test instance to see if that solve the problem ?  
I'm not much a node.js/npm expert, so guidance would be appreciated.

Or should I just forget Jsonata and move some Javascript code in a function node ?

Thanks

Easy to reproduce with

```auto
[{"id":"e6888c350c73926b","type":"inject","z":"e486c4ba444f3570","name":"$number(\"0x12\")","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$number(\"0x12\")","payloadType":"jsonata","x":340,"y":820,"wires":[["3f49c7d928059338"]]},{"id":"3f49c7d928059338","type":"debug","z":"e486c4ba444f3570","name":"debug 26","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":540,"y":820,"wires":[]}]

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/5/b51ba6df5931eb85b41a82aaf9a161d3dc40e263.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/3/a3c708a1aca2c626f6b8e97fbdcd858c1a11c1f0.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [17 April 2023 19:31 UTC](https://discourse.nodered.org/t/jsonata-number-hexstring-not-working/77672/2 "2023-04-17T19:31:45Z")

</div>

Try `$parseInteger("0x12", '0')`

I can't confirm if this is a node-red or error from JSONata, Maybe ask on the JSONata git issue page.

[edit] it does look like that is a new JSONata 2 added support for hex numbers.

> - Add support for parsing binary, octal & hexadecimal numbers (PR #573)

I think Nick and team are adding 2.0 in the summer, as far as i can remember.

---

<div class="post-metadata">

**Author:** ![Barbudor](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@Barbudor](https://discourse.nodered.org/u/Barbudor)\
**Post date:** [17 April 2023 21:08 UTC](https://discourse.nodered.org/t/jsonata-number-hexstring-not-working/77672/3 "2023-04-17T21:08:26Z")

</div>

Works perfectly so it doesn't seems to be v2

Indeed it was the last function on the same doc page but I didn't thought of scolling down as the 1st one look like it was good 🙂

Thanks a lot @E1cid

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [16 June 2023 21:08 UTC](https://discourse.nodered.org/t/jsonata-number-hexstring-not-working/77672/4 "2023-06-16T21:08:54Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
