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

后端 未结 13 2139
不思量自难忘°
不思量自难忘° 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条回答
  •  -上瘾入骨i
    2020-11-27 17:27

    function getDecimalSeparator() {
        //fallback  
           var decSep = ".";
    
            try {
                // this works in FF, Chrome, IE, Safari and Opera
                var sep = parseFloat(3/2).toLocaleString().substring(1,2);
                if (sep === '.' || sep === ',') {
                    decSep = sep;
                }
            } catch(e){}
    
            return decSep;
        }
    

提交回复
热议问题