Format currency not working

I try to format currency. Just adding the “prijs” fields will show the value. In the dbase field is set “double(8,2)”. After setting format there is no show. {{prijs.formatCurrency("€", ",", ".", 2)}}

Hi @web-works

The datatype might be wrong. Just a guess from a noobie but I’ve observed the same thing when the datatype is not set to Number #.

Edit: I just tested on my end in the latest version of wappler and it is working like a champ!


1 Like

You send me on the right track. I had to convert to number first and then format.
{{prijs.toNumber().formatCurrency("€ ", ",", ".", "2")}} This works perfectly

2 Likes

I noticed that when I change the data type to “number” from “text” (when my database structure reads text for the field) without using .toNumber() works sometimes.

It also enables numeric fields for the variable and simplifies your output.

You could have this:

happy_times

toNumber()
Round()
formatCurrency()
etc

Setting field as number from the option “Variable Properties” as @fatherofinvention pointed out reduces my variable to:

happy_times

formatCurrency (’’, ‘’, ‘0’)
(0 represents precision) where the decimals don’t matter.

In the least you have saved 16bytes +.

2 Likes

I tried that too, but didn’t work for me.