PDA

View Full Version : Round Off usning Ext3



rmdismail
5 Sep 2011, 8:15 PM
Hi Everybody!!!
I need to round of the amount using Extjs. My scenario is the round off decimal places will be dynamically changed. pls help me to implement this .

carol.ext
6 Sep 2011, 1:42 PM
Number rounding in javascript (http://www.javascriptkit.com/javatutors/round.shtml) - see link for details (this is how we do it, I googled to find a link with some explanation)


the formula to round any number to x decimal points is:

1) Multiple the original number by 10^x (10 to the power of x)
2) Apply Math.round() to the result
3) Divide result by 10^x

Uberdude
7 Sep 2011, 1:15 AM
There's also Number.toFixed(decimalPlaces), though there are some browser quirks. See http://www.merlyn.demon.co.uk/js-rndg1.htm for a thorough treatment of rounding in Javascript.