Kitz ADSL Broadband Information
adsl spacer  
Support this site
Home Broadband ISPs Tech Routers Wiki Forum
   Compare ISP   Rate your ISP
   Glossary   Glossary
Please login or register.

Login with username, password and session length
Advanced search  


Author Topic: javascript - rounding to 2 decimal places  (Read 455 times)


  • Reg Member
  • ***
  • Posts: 657
javascript - rounding to 2 decimal places
« on: March 01, 2019, 11:16:10 AM »

anyone any good with javascript?

i have a little script that counts the total of a column in a table

Code: [Select]
$(function () {
var TotalCoreProd = 0;
$("[id*=col01]").each(function () {
TotalCoreProd = TotalCoreProd + parseFloat($(this).html());

problem is, it's outputing the value with about 20 decimal places.
i need to round this to 2 decimal places.
i believe ".tofixed(2)" should be used, but no matter where i try and place it, it ends up causing the code the fail completely.


  • Just arrived
  • *
  • Posts: 9
Re: javascript - rounding to 2 decimal places
« Reply #1 on: May 20, 2019, 08:12:21 PM »

Bit late to the party but did you use toFixed with a capital F?

If not, it would cause a syntax error and wouldn’t run the code at all...