我能收集到的最好结果是 "The toFixed() Method"
best result i could gather has been "The toFixed() Method"
OS: 分OS7
我在我的本地服务器上 运行“OpenWebSpider v0.3.0”(对于 searching/indexing)。 ~它应该正常工作。当我收到“结果”时,它显示“相关性 XX.XXXXXXXXXXXXXX”。我想将其缩短为只有 3 个小数位; “XX.XXX”..
enter image description here
我是新来的,对这javascript有些了解。我想我找到了我需要嵌入的东西? toFixed() 方法,但我无法确定确切位置,或者就此而言,If 是完成这项看似简单任务的最佳方法。 ?:)
这是(我在想的)相关的“代码”区域。
enter image description here
作为这方面的新手,我尝试了各个领域进行编辑或只是添加:for (var i = 0; i.toFixed(2); i < results.length ; i++)
到上图的“代码区”(图2); (有很多变化)所有结果都是 none。到目前为止。
抱歉,如果我的“问题”不合规,我会解决的,我绝对尊重 Whosebug,它是什么..非常感谢。
好吧,如果你只想打印出小数位数减少的数字 toFixed() wil do fine. But notice that it will change your number to a string. One other way to do it would be to use Math.round ()。在您的情况下,要获得 3 位小数,它将是
Math.round(your_number * 1000) / 1000
.
还有你的循环。 for (var i = 0, i.toFixed(2); i < results.length; i++)
(假设第一个 ;
应该是 ,
)将不起作用,因为 i.toFixed(2)
不仅会在循环开始时执行一次,还会被应用到 i
这只是你的循环计数器。您需要在循环中像这样应用它:
results[i]['relevancy'].toFixed(3)
。
OS: 分OS7
我在我的本地服务器上 运行“OpenWebSpider v0.3.0”(对于 searching/indexing)。 ~它应该正常工作。当我收到“结果”时,它显示“相关性 XX.XXXXXXXXXXXXXX”。我想将其缩短为只有 3 个小数位; “XX.XXX”..
enter image description here
我是新来的,对这javascript有些了解。我想我找到了我需要嵌入的东西? toFixed() 方法,但我无法确定确切位置,或者就此而言,If 是完成这项看似简单任务的最佳方法。 ?:)
这是(我在想的)相关的“代码”区域。
enter image description here
作为这方面的新手,我尝试了各个领域进行编辑或只是添加:for (var i = 0; i.toFixed(2); i < results.length ; i++)
到上图的“代码区”(图2); (有很多变化)所有结果都是 none。到目前为止。
抱歉,如果我的“问题”不合规,我会解决的,我绝对尊重 Whosebug,它是什么..非常感谢。
好吧,如果你只想打印出小数位数减少的数字 toFixed() wil do fine. But notice that it will change your number to a string. One other way to do it would be to use Math.round ()。在您的情况下,要获得 3 位小数,它将是
Math.round(your_number * 1000) / 1000
.
还有你的循环。 for (var i = 0, i.toFixed(2); i < results.length; i++)
(假设第一个 ;
应该是 ,
)将不起作用,因为 i.toFixed(2)
不仅会在循环开始时执行一次,还会被应用到 i
这只是你的循环计数器。您需要在循环中像这样应用它:
results[i]['relevancy'].toFixed(3)
。