With a browser, how do I know which decimal separator does the operating system use?

后端 未结 13 2172
不思量自难忘°
不思量自难忘° 2020-11-27 17:05

I\'m developing a web application.

I need to display some decimal data correctly so that it can be copied and pasted into a certain GUI application that

13条回答
  •  醉酒成梦
    2020-11-27 17:23

    Similar to other answers, but compressed as a constant:

    const decimal=.1.toLocaleString().substr(1,1);      //returns "." in Canada
    

    Also, to get the thousands separator:

    const thousands=1234..toLocaleString().substr(1,1);   //returns "," in Canada
    

    Just place the code at the top of your JS and then call as required to return the symbol.


    For example (where I live), to remove commas from "1,234,567":

    console.log( "1,234,567".replaceAll(thousands,"") ); //prints "1234567" to console.  
    

提交回复
热议问题