四舍五入 [英] Round off
问题描述
有没有人找到一种可靠的方法来强制JS转到特定数量的
位置?我每次尝试都会得到不同的结果。例如,我需要
回合3.4589到2个位置。什么是最可靠的方法呢?
谢谢
-S
Has anyone found a reliable way to force JS to round to a specific number of
places? Every time I try I get different results. For example, I''d need to
round 3.4589 to 2 places. What is the most reliable way to do it?
Thanks
-S
推荐答案
Phat G5(G3)在2006年4月4日下午6:35发表以下内容:
Phat G5 (G3) said the following on 4/4/2006 6:35 PM:
有没有人找到一种可靠的方法来强制JS轮流到特定数量的地方?
是的。
每次尝试我都会得到不同的结果。
然后你做得不对。
例如,我需要将3.4589舍入到2个位置。
嗯。我似乎记得小组常见问题解答中关于四舍五入到$
的地方。
< URL: http://jibbering.com/faq/#FAQ4_6 >
最可靠的方法是什么?
Has anyone found a reliable way to force JS to round to a specific number of
places?
Yes.
Every time I try I get different results.
Then you aren''t doing it right.
For example, I''d need to round 3.4589 to 2 places.
Hmmm. I seem to recall something in the group FAQ about rounding to 2
places.
<URL: http://jibbering.com/faq/#FAQ4_6 >
What is the most reliable way to do it?
最可靠?在Usenet上发帖,并询问如何让某人指向你发布给你的小组的常见问题解答
。
-
Randy
comp.lang.javascript常见问题 - http:/ /jibbering.com/faq &新闻组每周
Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /
Most reliable? Post in Usenet and ask how to do it to have someone point
you to the FAQ of the group you post it to.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
JRS:文章< C0 ******************* @ noone.com>,日期为4月4日星期二
2006 15:35:52远程,见于新闻:comp.lang.javascript,Phat G5(G3)
<无**** @ noone.com>发表:
JRS: In article <C0*******************@noone.com>, dated Tue, 4 Apr
2006 15:35:52 remote, seen in news:comp.lang.javascript, Phat G5 (G3)
<no****@noone.com> posted :
有没有人找到一种可靠的方法来强制JS转到特定数量的
位置?我每次尝试都会得到不同的结果。例如,我需要将3.4589轮到2个地方。最可靠的方法是什么?
Has anyone found a reliable way to force JS to round to a specific number of
places? Every time I try I get different results. For example, I''d need to
round 3.4589 to 2 places. What is the most reliable way to do it?
在发布之前阅读新闻组常见问题解答,并找到IIRC,其中部分
4.6其中。
您的最可靠是一个毫无意义的词;一种方法是可靠的
(可能在规定的范围内)或者是错误的。
请记住银行家的舍入。问题,以及
确切值可以采用的限制。
当然,如果您的3.4589是一个字符串,则应采用不同的方法<考虑
。
-
?约翰斯托克顿,英国萨里。 ?@merlyn.demon.co.uk Turnpike v4.00 IE 4?
< URL:http://www.jibbering.com/faq/> JL / RC:新闻常见问题:comp.lang.javascript
< URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr数学,日期,来源。
< URL:http://www.merlyn.demon.co.uk/> TP / BP / Delphi / jscr /& c,FAQ项目,链接。
By reading the newsgroup FAQ before posting, and finding, IIRC, section
4.6 therein.
Your "most reliable" is a pointless term; either a method is reliable
(perhaps within stated limits) or it is wrong.
Remember the "Banker''s Rounding" question, and the limitations on which
exact values a Number can take.
Of course, if your 3.4589 is a String, a different approach should be
considered.
--
? John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ?
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
" Phat G5(G3)" <无**** @ noone.com>在消息中写道
新闻:C05842D8.33E67%没有**** @ noone.com ...
"Phat G5 (G3)" <no****@noone.com> wrote in message
news:C05842D8.33E67%no****@noone.com...
有没有人找到一种可靠的方法来强制JS舍入到具体数量
的地方?我每次尝试都会得到不同的结果。例如,我需要将3.4589轮到2个地方。最可靠的方法是什么?
Has anyone found a reliable way to force JS to round to a specific number of places? Every time I try I get different results. For example, I''d need to
round 3.4589 to 2 places. What is the most reliable way to do it?
有些人觉得满意:
将数字乘以100,然后围绕它然后把它除以100.
有些人宁愿在一个善意的问题上讨厌一个人 -
或一个善意的答案 - 就像这样。
(来了,我很有信心)
Some folks find it satisfactory to:
multiply the number by 100, then round it , then divide that by 100.
Some folks rather hassle a person over a well-meant question -
or a well-meant answer - like this.
( here it comes, I''m sure)
这篇关于四舍五入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!