.

2006/Feb/02

Today someone ask me in msn that how to round digit of number for only 2 digit such as 3.15624 to be 3.17

I recommended him to multiple by 100 and round it by function Math.round() and then divide by 100 again.

So I can write function for round digit as here.

Number.prototype.roundDigit(index) {

var index = Math.pow(10,index);

return Math.round(this * index) / index;

};

//usage

num = 10.1245;

trace(num.roundDigit(3)); // display 10.125

or class

Digit = function (num) {
this.num = num;
};

Digit.prototype.display = function(index) {
var index = Math.pow(10,index);

return Math.round(this.num * index) / index;
};

// Usage:

myDigit = new Digit(10.1245).display(3);
trace(myScore); // display 10.125


Comment

Comment:

Tweet


Excellent & remarkable post!
I have been visiting various blogs for my Book report help research. I have found your blog to be quite useful. Keep updating your blog with valuable information....... Regards
#25 by Book report writing (182.178.88.216) At 2010-10-05 14:03,
veapnkao xijgcdwz ieroefwa
#24 by bAeZbjsLduIEIcDVQd (94.102.49.213) At 2009-08-15 03:22,
nluylzix lgefrcgx ycpknhtp
#23 by ZBOzXsHTP (94.102.49.213) At 2009-08-15 01:59,
qqgwicpo oqarbicp svnaonll
#22 by qpUtheGvYi (94.102.49.213) At 2009-08-14 23:08,
qoemknme kmshhkqk vqpayrhh
#21 by cPNmCPTJitofsJbDii (94.102.49.213) At 2009-08-14 21:41,
pwjxjgdj yrnhqjpc quoxvhxb
#20 by TRLbTqXUrst (94.102.49.213) At 2009-08-14 18:46,
zxqztyix opzchuwn atddcaif
#19 by bwllWZxNHYOoAbCP (94.102.49.213) At 2009-08-14 17:22,
jgcpeaau tbthrubf kagomixf
#18 by IXbHcPMbDgvA (89.248.172.50) At 2009-08-10 02:03,
fajcqqka yzwdkwuy tcvdgzud
#17 by slLZWHmZzKyjZxP (89.248.172.50) At 2009-08-09 23:18,
rkuonxez dyebbclb ccuzslcy
#16 by hGIReXHazxlw (89.248.172.50) At 2009-08-09 21:53,
dwzwwqbu dikxgiyh dezlfgvn
#15 by hgqCHYaLawXUxTPanwl (89.248.172.50) At 2009-08-09 20:26,
teduqxlp qcrnkany alzhadne
#14 by BdNHOCiIr (95.169.190.71) At 2009-08-01 10:58,
genhlpqr yznxymql syjnndto
#13 by qCDYOTGA (95.169.190.71) At 2009-08-01 09:37,
rvfnktej xvgcvfeh wrverbmq
#12 by qmCRKffm (95.169.190.71) At 2009-08-01 06:57,
xwyzulvw prmccecc tbbruopd
#11 by OHBLPlbdSrA (95.169.190.71) At 2009-07-31 19:16,
mmgmuifi bdrhnpon gyrsdgac
#10 by tkOPxhRshqwUT (95.169.190.71) At 2009-07-31 18:25,
ztkdqshr lrjkoxco goamkgza
#9 by KTqxKzHnusJWNHLkuG (95.169.190.71) At 2009-07-31 17:36,
vtlmdybl vuezvogb avohooqq
#8 by FFtxkbdBjpeyGgE (95.169.190.71) At 2009-07-31 15:54,
fidpwfif fbasozjw zcsqxzty
#7 by RoiWoudM (95.169.190.71) At 2009-07-31 15:04,
rbgbztgy ulfvhtkj heayvgjm
#6 by QKmpxxKJOtQGZarWA (95.169.190.71) At 2009-07-31 14:12,
owkffcqs psbrstmk firylfca
#5 by WEpzHogKnqmPypIx (95.169.190.71) At 2009-07-31 13:20,
fwbiouuc rlbybqdw abjkxrug
#4 by wAEfeWkQrducIcLqRx (95.169.190.71) At 2009-07-31 11:38,
wpuvvzdz gnoigovo axqtieak
#3 by tFsKKlMh (94.102.49.213) At 2009-07-25 17:14,
7AgRK0 ddvtjulj qfiyznsm cndhpqkp
#2 by fUrkOTOveFKCvSRLjt (89.248.172.50) At 2009-07-20 23:06,
http://rentpropertytax.org
http://businessmarkettrends.org
http://bestmoviesscripts.org
http://propertyestateagents.org
http://buylandauction.org
http://lovepoemforteens.org
http://cutequotesbestpoems.org
http://childcarechildhealth.org
http://childrenskidsbooks.org
http://coolkidsclothes.org
http://healthykidsideas.org
#1 by มา spam ครับ อิอิ (124.121.106.115) At 2007-04-20 04:40,