I need to pass a dynamic variable as a number and not as a string

Windows 10pro
Server PHP, Mysql
Wappler 4.1.1

Hi guys I don’t know how to pass a dynamic value as number to API
As soon as I put double quotes, the api returns error
and if I remove the double quotes the wappler won’t let me save a action

I need to pass a dynamic variable as a number and not as a string

Please does anyone know how to fix this?

Maybe try formatting using the Conversion Formatter option to convert the string to Number?

I think the issue is that you have to wrap any value in quotes in the json editor which then makes it a string, even if it started as a number or was even converted to a number. I’ve only ever been able to get around this using a custom formatter to return the correct json structure - would welcome any ideas/suggestions on this

is it not because your VALOR | NUMBER might be an integer… ???
Maybe try to make this instead of a INTEGER maybe DOUBLE in your database?

So it produces… say, " 10.55 " see if that works…
As your API maybe require the amount to have a decimal break… just a thumb suck

A quick test would be… just SET another value … to say … 10.55
then use that SET value in the API… if that works… then you know :slight_smile:

I think this is an issue (more like something that could be improved) in the Wappler UI that requires bound data to be wrapped in quotes in the JSON editor. @george could you take a look?

the problem is having to put in quotes making it a string

The problem is to be forced to put in quotes making it a string and the external api doesn’t accept
@patrick

Some position on this I need to finish my project and I don’t know how
@Teodor @patrick

There is a workaround you could try which is to use a custom formatter.

You would need to write some PHP to take the values as parameters and then make the array structure before returning the array to SC but it shouldn’t be too difficult

Use {{plano.valor.toNumber()}}. MySQL returns decimal fields as string since there is no equal type in PHP, converting a decimal to float could cause lost of precision.

But the issue is in the Wappler UI. You can’t add that to a JSON without putting it in " " rendering as a string when sent - the API in this case then rejects it as a string and not a number

1 Like

exactly

But the issue is in the Wappler UI. You can’t add that to a JSON without putting it in " " rendering as a string when sent - the API in this case then rejects it as a string and not a number

this is exactly the problem

hello @patrick any solution to this problem?

When you have "unit_price": "{{plano.valor.toNumber()}}" it will parse the expression in the string and should return the number, not a string. Make sure there the expression is as above, having a space inside it like "{{plano.valor.toNumber()}} " will return a string.

2 Likes

I often put numbers in the JSON with the quotes and it does actually render correctly as a number without the quotes when it gets to the API endpoint.