AC Formatter reading numbers as text (therefore formatting options do not appear or fail)

Wappler Version : 4.12
Operating System : Mac
Server Model: Node
Database Type: Postgres
Hosting Type: Docker local

Expected behavior

What do you think should happen?

Create a DB Query SC that outputs numbered data, in this case i’m using ‘Aggregate’ in the DB and ‘sum’ is the SUM Aggregate and ‘count’ is a COUNT aggregate.

The original field type for ‘sum’ in the DB is decimal. The naming ‘sum’ is an alias of the real field name.

I should then be able to use the AC Data picker to format that number (e.g. removing decimal places for the UI).

Actual behavior

What actually happens?

Data Picker views the number output as an ‘A’ and therefore only gives me text formatting.

See query output in AC:

Screen Shot 2021-07-13 at 4.04.17 pm

Both here should actually appear as a number.

However when I click on the number field ‘sum’ and use the magic wand:

It displays the type as ‘text’.

If I change type to number - the output on the page doesn’t perform (blank) whereas if I leave without formatting it displays on page.

So are there any errors in the console?
What value do you see when you run the server action directly in the browser - most probably it just returns a string and that’s why you don’t see the numeric formatters for it. So when you try to apply them, you probably see “Not a number” warning in the console.

Hi @Teodor - thank you for the reply.

You are right - this is outputting as a string.

So, what is going on here? The DB Field is a decimal, i’m using the ‘SUM’ aggregator - and in the AC Data Picker it initially shows this field as a number - then when I go to use the formatter - it believes it’s a string?

What am I doing wrong / need to improve here?

Just convert to number first and then apply the numeric formatters to it.

Thanks Teodor. I’ll do that.

Is this expected behaviour, even though the field in the DB itself starts off as a decimal type? I would have assumed if the DB field is a type of number that the formatters should see it as such?

Just for my information.

If you don’t see this as a bug, feel free to unlist.

Yes it is the expected behavior. The decimal values do not fit the JavaScript number type so it becomes a string.
You need to convert them to number if you want to apply numeric formatters to them or do any calculations.

1 Like

Thank you for the explanation Teodor. It’s appreciated.