Bug on formatCurrency

Hi
Using latest wappler 3.3.6, windows 10.

Seem to have odd bug on formatting dynamic number.

so this value returns the correct number:

{{sc_UserJobSummary.data.q_UserJob_sel[0].balancepaid}}

(so it contains data)

{{sc_UserJobSummary.data.repeat1[0].balancepaid.formatCurrency(’$’, ‘.’, ‘,’, 2)}}

gives nothing, just blank. Same happens if I use formatNumber

thanks
Darren

Hi,

Two questions:

  1. Was this working in previous version?
  2. Do you see any warning or error in the browser console when format current or format number formatter is set?

cant say about previous version as just something I wanted in place on the site I am working on that I worked on this morning.

No errors anywhere that I can see

thanks

The code you have posted looks to have incorrect single quotes. It could be just a copy-paste issue. But still, if you could check. This is how it looks where I have used it:
formatCurrency('$', '.', ',', 0)

I haven’t been able to update my Wappler yet. It downloads really-really-really slowly due to some CDN/ISP issues. So can’t test on my system to confirm if this is an issue on the project where I am using this.

the code was generated by wappler and copy pasted directly from the wappler code into here.
thanks

In that case…
{{sc_UserJobSummary.data.repeat1[0].balancepaid.formatCurrency(’$’, ‘.’, ‘,’, 2)}}

Try replacing above with this:
{{sc_UserJobSummary.data.repeat1[0].balancepaid.formatCurrency('$', '.', ',', 2)}} in code view.

found a bug in browser after putting code back in and running again

Formatter formatCurrency in expression [sc_UserJobSummary.data.q_UserJob_sel[0].balancepaid.formatCurrency(’$’, ‘.’, ‘,’, 2)] doesn’t exist for type string

So you need to convert it to number first, as the value seems to be a string.

1 Like

That’s exactly the error I was assuming to be present in the console. :sweat_smile:
Just use balancepaid.toNumber().format....
You can find the to number formatter in action picker UI.

in the DB its a decimal(10,2). When I set it up to format I selected number (as its only then that you get the option to format it to a currency). So it should be a number format shouldnt it?

thanks
D

thanks, the toNumber worked, but still like to know why it didn’t work with native wappler as its a decimal in the DB and its set to number in wappler to format as currency.

Cheers
D

Thats a mystery since day 1. Never bothered to make a post or ask to be honest. Have seen it many times myself. Maybe something to do with supporting multiple types of SQL Servers.
Maybe @Teodor can shed some light on it.

It is indeed mysterious. I copied a file from an old site to a new one recently and just noticed the price field, with currency formatting applied, was empty. I compared this with the site I had copied it from and couldn’t see any obvious difference; the versions of dmxFormatter.js were the same etc. Once I added toNumber(), all was well - but this wasn’t needed before, in the original site which still works fine. The two files are identical.

The toNumber formatter requires a number as input, so probably the value used in the new site was not a number but a string. Problem often is the database driver, in some cases it returns a string for number fields and that is something you would not expect. It depends on different combinations, for example an BIGINT often converted to string in PHP since it doesn’t support 64 bit. And so there are more cases of numbers being returned as strings by the database.

Thanks Patrick. In this case, the database and server, and pretty much everything else is the same. The database for the second site is a copy of the first and the field in question is defined as an integer. I usually would use toNumber straightaway in such cases, but as this was file was copy/pasted from another site, I was puzzled that it didn’t work. Anyway, there’s a simple solution to the problem.