Number formating in an experience Workflow

Context: There is data that gets converted into a CSV in an experience workflow, downloaded and later will be displayed in Excel in a western european country.

The intended Formating is e.g.: 12345,6789.
Right now the formating is: 12345.6789

While searching in the forum I came across the Format helper:

Format helper rounding to specific number of decimal on a number - Workflow Lab - Losant Forums

In the dahboards in the bowser the numers are formated correctly. As described in the docs , the locale of the browser is used for the formating.
Accessing Payload Data | Losant Documentation

Here I am however working in an experience workflow. Therefore there is no browser locale and the default seems to be the format described (1.2 not 1,2) above. How do I get the right format of a number (localized) in a workflow, stored in the payload?

I spent some time playing with the {{format}} helper and could not come up with a way to pass a format that would give you your desired result. I am going to file a feature request to add an optional locale argument to the helper for this use case.

I do have a workaround: JavaScript’s native toLocaleString() method. Attached is a workflow that demonstrates how you could use it in a Function Node to loop over all your raw numbers and convert each to a localized string to get the result you are after for your CSV.

One question I would add - You said this CSV will ultimately be consumed by your end users in Excel. If that is the case, would it be better to instead write the raw number (12345.6789) and allow Excel to do the formatting? Excel typically handles formatting numbers onscreen using the appropriate locale already, and it also allows for operating on the values in that column as numbers (sorting, formulas, etc.). What you would be doing here is converting the number to a string, and I actually do not know if Excel would be able to parse that string into a number for those purposes.

format-locale-develop.flow (1.7 KB)

Regarding Excel: Yes, there are ways to import data in a CSV format and have Excel adjusting the format. You, however, need to take a few extra steps to make it work. It would be nice to be able to double click the CSV file and have it open in the correct format right away.

The toLocaleString() method does work nicely. As a context: I use a “Data: Time Series Query” to get device data. So it is a dictionary with some Stings and some numbers, that I am trying to format. While looping over every point (dict with multiple entries) the following JavaScript inside of a functionNode is executed:

var dataPointValues = payload.working.thisPoint.value.data;

for (let k in dataPointValues) {
    var v = dataPointValues[k];
    if(typeof v == 'number'){
        payload.working.thisPoint.value.data[k] = v.toLocaleString('en-DE', {minimumFractionDigits: 4});
    }
}

While it gets the job done, it is very slow. Is there a more elegant and (more importantly) better performing way to write this code?

Based on the property names, it seems like that Function Node is being used inside of a Loop Node, which is one of our cardinal sins of workflow performance :slight_smile: .

Is it possible to rearrange your workflow so that you utilize a single Function Node, outside of a loop, to do this operation on every data point inside of one node? You will see a massive performance improvement if so.

Guilty as charged.
I will fix that.
Thank you!