- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
根据 this MDN page , toLocaleString
是关于转换日期的。但是,Chrome 不仅仅在字符串上公开该函数。例如:
a = function () {};
a.toLocaleString(); // "function () {}"
toLocaleString
是什么?例如,为什么它会暴露在空函数上?
最佳答案
也是available在 Object.prototype
上,所以间接地在几乎任何东西上。
对于 Chrome,您可以查看 V8's implementation ,它没有做任何花哨的事情:
function ObjectToLocaleString() {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
throw MakeTypeError("called_on_null_or_undefined",
["Object.prototype.toLocaleString"]);
}
return this.toString(); // <-- just calls toString
}
关于javascript - 什么是 toLocaleString()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12167796/
我的 JavaScript toLocaleString() 在这里做了一些奇怪的事情。如果我有一个小于 1000 的数字,它会给我一个点作为小数分隔符,但如果我有一个大于 1000 的数字,它会给我
在 Javascript 中,我尝试使用 toLocaleString() 将 Date 对象转换为语言环境字符串。功能。我想要的是以毫秒为单位的转换后的语言环境字符串。那可能吗? const tim
我正在使用一个非常简单的脚本来格式化数字: gst = '123.45'; currency = 'EUR'; money = gst.toLocaleString('en-US', { styl
我想在用户输入时为数字添加千位分隔符。这是我的代码: $('.rls').on('input',function (e) { $(this).val(parseFloat($(t
我在这里不知所措。我需要在我的区域设置中显示 JavaScript 日期,但显示的区域设置字符串在未来 1 个月内关闭。 var d = new Date(2018,4,3,21,0); d
我想知道如何有效地从价格中删除小数点零,同时保留两位小数(如果有的话) 所以如果价格是 135.00,它应该变成 135。 如果价格是 135.30 但是它应该保留两个小数点。 如果价格是 135.3
你好,我有一个问题: Number.prototype.toLocaleString() 问题是,当我们使用“toLocaleString()”方法时,如果有“0”,它不会显示最新的 maximumF
我有这个测试代码片段: ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn"); Object o = e
.toLocaleString() 适用于我的整数数据类型;但是,它不适用于带小数的数字。 我有一些大的货币数字,我将它们除以 1000 以千位和 .toFixed(1) 小数点表示。所以 13153
我正在尝试以用户喜欢的格式打印日期/时间。我有: options = { day: "numeric", year: "numeric", month: "short", time: "short",
在我看来,javascript 的数字 toLocaleString() 和 .NET ToString() 数字格式不同。 toLocaleString() 似乎忽略了我在工具/Internet 选
更新: 原文: 你能告诉我为什么 toLocaleString() 在这里不起作用吗?它适用于所有其他地方。我需要它来提供 1000 个分隔符。任何线索或解决方法? forEach(budgetLi
我对 toLocaleString 方法的奇怪行为有点困惑。请有人帮忙修复它。 例如下一个代码可以正常工作: let value = "2018-11-26T10:00:00.000Z"; let d
我做了一个小函数,将 UNIX 时间戳转换为 Date 对象。然而,返回的字符串总是早 2 小时。 toDateTime(secs) { var t = new Date(1970, 0, 1
var num = 1239128938213092131823; num.toLocaleString('en-IN', { maximumSignificantDigits: 3, style:
根据 this MDN page , toLocaleString 是关于转换日期的。但是,Chrome 不仅仅在字符串上公开该函数。例如: a = function () {}; a.toLocal
我正在做一个项目,我必须处理很多日期和时间问题。服务器端技术是 ASP.Net,在客户端我使用 jQuery 和 jQuery Week Calendar(一个 jQuery 插件)。 所以这是描述的
这个问题在这里已经有了答案: Internationalization(Number formatting "num.toLocaleString()") not working for chrome
我需要在 JavaScript 中使用可以在运行时定义的分隔符来格式化一个数字。 千位和小数分隔符的组合可能与特定的语言环境不匹配。 有没有办法在 JavaScript toLocaleString(
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString说:
我是一名优秀的程序员,十分优秀!