四舍五入的数字 [英] rounding off numbers
问题描述
是否有一个脚本可以将数字四舍五入到一定数量的
小数位? -Allen Thompson
文章< Lx ************* @ newsread2.news.atl.earthlink达网络> ,艾伦
汤普森< ge ******** @ mindspring.com>写道:
是否有一个脚本可以将数字四舍五入到一定数量的小数位? -Allen Thompson
1.设x =你想要的小数位数。
2.将数字乘以10上升到x。
3.在答案上使用Math.round()。
4.除以2中获得的数字。
>
-
Dennis M. Marks
----- =通过Newsfeeds.Com发布,未经审查的Usenet新闻= -----
http://www.newsfeeds.com - 世界排名第一的新闻组服务!
----- ==超过100,000个新闻组 - 19个不同的服务器! = -----
Dennis M. Marks写道:文章< Lx ********** ***@newsread2.news.atl.earthlink.net> ,艾伦
汤普森< ge ******** @ mindspring.com>写道:
是否有一个脚本可以将数字四舍五入到一定数量的小数位? -Allen Thompson
1.设x =您想要的小数位数。
2.将数字乘以10乘以x。
3.在答案上使用Math.round()。
4.除以2中获得的数字。
或使用toFixed()方法Number对象:
nofollowhref =http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/number.html#1193137 target =_ blank> http://devedge.netscape.com/library/...r.html#1193137
在文章< br ********** @sparta.btinternet.com> ;, bagbourne< no *** @ noway.com>
写道:
< blockquote class =post_quotes> Dennis M. Marks写道:
< - snip - >
或使用toFixed()方法Number对象:
alert((0.007).toFixed(2)
//给出0.00
将它降低到两位小数,*不*舍入它。
-
兰迪
Is there a script that will round off a number to a certain number of
decimal places? -Allen Thompson
In article <Lx*************@newsread2.news.atl.earthlink.net> , Allen
Thompson <ge********@mindspring.com> wrote:
Is there a script that will round off a number to a certain number of
decimal places? -Allen Thompson
1. Let x = the number of decimal places you want.
2. Multiply the number by 10 raised to x.
3. Use Math.round() on the answer.
4. Divide by the number obtained in 2.
--
Dennis M. Marks
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Dennis M. Marks wrote:In article <Lx*************@newsread2.news.atl.earthlink.net> , Allen
Thompson <ge********@mindspring.com> wrote:Is there a script that will round off a number to a certain number of
decimal places? -Allen Thompson
1. Let x = the number of decimal places you want.
2. Multiply the number by 10 raised to x.
3. Use Math.round() on the answer.
4. Divide by the number obtained in 2.
or use the toFixed() method of the Number object:
http://devedge.netscape.com/library/...r.html#1193137
In article <br**********@sparta.btinternet.com>, bagbourne <no***@noway.com>
writes:
Dennis M. Marks wrote:
<--snip-->
or use the toFixed() method of the Number object:
alert((0.007).toFixed(2)
//gives 0.00
Which is dropping it to two decimal places, *not* rounding it.
--
Randy
这篇关于四舍五入的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!