javascript - What is a Locale String? - Stack Overflow

I've been looking through A re-introduction to javascript and came across the array method toLocal

I've been looking through A re-introduction to javascript and came across the array method toLocaleString().

I did some googling (something to do with localization?) but am having difficulty figuring it out.

What is a locale? What's the difference between toString() and toLocaleString() in javascript?

I've been looking through A re-introduction to javascript and came across the array method toLocaleString().

I did some googling (something to do with localization?) but am having difficulty figuring it out.

What is a locale? What's the difference between toString() and toLocaleString() in javascript?

Share Improve this question asked Feb 26, 2015 at 7:43 Luke DieboldLuke Diebold 1532 silver badges10 bronze badges 1
  • It's like how dates or numbers are written differently amongst languages, like American (mm/dd/yyyy) vs British (dd-mm-yyyy) which can be observed with Date.prototype.toLocaleString(). – Ja͢ck Commented Feb 26, 2015 at 7:45
Add a ment  | 

1 Answer 1

Reset to default 4

toString() this will just convert the string format without any conversion at all (unless you try to overwrite it).

toLocaleString() will convert to string format and apply a conversion base on Locale. Example: if your Locale is set to US (U.S. English locale)

var number = 3500
console.log(number.toLocaleString());

This will print (in the console): "3,500". But if you were using only toString() you would get "3500" (without the ma for the thousands).

It works for currencies, dates, times, etc...

More information here: https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745572956a4633792.html

相关推荐

  • javascript - What is a Locale String? - Stack Overflow

    I've been looking through A re-introduction to javascript and came across the array method toLocal

    19小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信