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.
Any change we can get automatic convert toNumber() automatically by Wappler for this?
Imagine you have thousands of tables with decimal value and thousands of calculations - and you need .toNumber() to each of them?
I do lots of decimal calculations in server actions… after the database query, I just do a series of Set Value commands that include the .toNumber() and then do the calculations based on those values…
Set Value amount_invoiced = get_invoice.amount_invoiced.toNumber()
Set Value amount_unpaid= get_invoice.amount_unpaid.toNumber()
Set Value amount_sales_tax= get_invoice.amount_sales_tax.toNumber()
...
In this situation, you would be better to create a database View and do the calculations there…
Database Views are the least talked about and most powerful feature I know!
There are lots of videos on YouTube about them… if you have lots of database tables to combine for a given collection of data to work with they are absolutely amazing…
Personally I am not a fan of views.
Views are effectively a general query at db level providing a “pseudo” table.
If their result is exactly what you need the that’s fine.
If you query a view you add a second level of processing which, in many cases, can not be effectively optimised by the DB engine.
I would almost always look to use a query in preference to a view for these reasons.
If you are not worried about the performance hit then yes, they can make things easier
Parameterised stored procedures are more effective
Hi there Brian!
For views that don’t use aggregate functions there I have found no noticeable performance issues… and if I need an aggregate function I just do it in the server action instead of the view.
This gain is rapidly lost once you start to employ formatters on the Client side. Far better to do that within the database itself, especially in the case of numbers, and lots of them (currency and calculations). For us its swings and roundabouts as if you are utilising a well configured database server the performance loss you mention is minuscule (and the performance gains can be considerable), in comparison to rendering speed impact with formatting the data in the browser.
@Antony But what about calculation with DECIMAL values? Does “views” can handle them?
Biggest problem is that wne you trying to do a SUM, for instance DECIMAL + DECIMAN - it becomes as string in Wappler and you have to add DECIMAL.toNumber() in to every calclation in your backend.
Absolutely, I avoid any type of client side processing where possible, especially the likes of “where” clauses in favour of subtables and multi references which added huge performance benefits. Very little cant be done with a query now.