# ASP.NET,C#.NET,VB.NET,JQuery,JavaScript,Gridview

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

### jQuery Round Off Number to Two (2) Decimal Places using toFixed(), toPrecision Functions

Mar 11, 2015
Introduction

Here I will explain how to use
jQuery to round off numbers to two or 2 decimal places example using JavaScript toFixed() or toPrecision() functions or jQuery round off number with two or more decimal values using JavaScript toFixed() or toPrecision() functions.

Description: jQuery fixed header on window scroll with example, jQuery currency conversion as per exchange rates and many articles relating to AngularJS, . Now I will explain how to round off numbers to two or 2 decimal places example using JavaScript toFixed() or toPrecision() functions in jQuery.

By using toFixed() or toPrecision() JavaScript function we can round off (roundup or rounddown) numbers with decimal values using jQuery like as shown below

toFixed() function will maintain specified number of decimals

 var fixval = 18564.56826; fixval.toFixed();    // Returns "18564" note: rounding, no fractional part fixval.toFixed(1);   // Returns "18564.6" note: rounding fixval.toFixed(4);   // Returns "18564.5482" note: rounding fixval.toFixed(6);   // Returns "18564.548260" note: added zeros
toPrecision() function will format number to specified length

 var precval = 250.568; precval.toPrecision();    // Returns "250.568" note: displays original number no rounding precval.toPrecision(4);   // Returns "250.6" note: returns 4 numbers precval.toPrecision(5);   // Returns "250.57" note: returns 5 numbers precval.toPrecision(6);   // Returns "250.568" note: returns 6 numbers

If you want to check it in complete example you need to write the code like as shown below

 jQuery Roud off numbers
Enter Number:
Result:
Live Demo

For live demo enter number with decimal value in below textbox and click button to round off numbers using toFixed() and toPrecision() functions

 Enter Number: Result:
Note: toFixed() will give you fixed number of decimal places and toPrecision() will give you specified length of numbers
 If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. Subscribe by RSS Subscribe by Email