toLocaleString



  • I've got a requirement to get the clients report to render decimal values in the Dutch format which is comma instead of dot and vise versa. So a value of 1,234.56 should be rendered as 1.234,56.

    What I have tried:

    The report template
    (productKg = 1.1)

    {{locale productKg}} 
    {{locale 1.123}} 
    

    Handlebar

    Handlebars.registerHelper('locale', (value) => value.toLocaleString('nl-NL'));
    

    The result in the report
    1.1
    1.123

    Expected result
    1,1
    1,123


  • administrators

    @rdkleine hi! which version of node.js are you using?



  • Node
    v14.15.0

    jsreport
    v2.8.0

    *I'm running jsreport in Docker


  • administrators

    i see, using toLocaleString relies on the icu information of the node.js version, in normal case using nodejs 14.15.0 is enough because it comes with the full icu information so all locales should work ok here. i did a simple test and this works ok with 14.15.0

    0_1611851797813_Captura de pantalla 2021-01-28 a la(s) 11.31.41 a. m..png

    *I'm running jsreport in Docker

    this is probably the problem for your case, you have nodejs 14.15 installed however if you use the docker container then you end up using the nodejs version which is specified in the Docker build, which in the case of the jsreport 2.8.0 is nodejs 12, which does not come with the full icu needed to support all locales.

    what you can try is make a custom docker image taking out image as the base, then you just need to change the nodejs version to node >=14.14 in that image



  • Ok, that explains it thanks!

    Are the docker versions > 2.8.0.0 using node > 14.14 by any chance?


  • administrators

    Are the docker versions > 2.8.0.0 using node > 14.14 by any chance?

    no, we still use node 12 even on the latest version (2.11), we plan to upgrade the node.js version there in the next major version


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.