Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6835521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:14:32+00:00 2026-05-26T23:14:32+00:00

Have a quick JS question. What is the difference between math.round and parseInt? I

  • 0

Have a quick JS question. What is the difference between math.round and parseInt?

I made a JS script to sum the inverses of prompted numbers:

    <script type="text/javascript">
    var numRep = prompt("How many repetitions would you like to run?");
    var sum = 0; 
    var count = 0;
    var i = 1;     //variable i becomes 1


    while (i <= numRep)  {//  repeat 5 times

       var number = prompt("Please enter a non zero integer");

       if(number==0){
         document.write("Invalid Input <br>");
 count++;
       }
       else{
          document.write("The inverse is: " + 1/number + "<br>");
          sum = sum + (1/parseInt(number));  //add number to the sum
       }

       i++; //increase i by 1
    }

    if (sum==0){
    document.write("You did not enter valid input");}
    else { document.write("The sum of the inverses is: " + sum);  //display sum
    }
    </script></body></html>

and it uses parseInt. If I wanted to makeit use math.round, is there anything else I need to do so that It knows to limit the number of decimal places accordingly?

In other words, does math.round have to be formatted in a certain way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:14:33+00:00Added an answer on May 26, 2026 at 11:14 pm

    The two functions are really quite different.

    parseInt() extracts a number from a string, e.g.

    parseInt('1.5')
    // => 1
    

    Math.round() rounds the number to the nearest whole number:

    Math.round('1.5')
    // => 2
    

    parseInt() can get its number by removing extra text, e.g.:

    parseInt('12foo')
    // => 12
    

    However, Math.round will not:

    Math.round('12foo')
    // => NaN
    

    You should probably use parseFloat and Math.round since you’re getting input from the user:

    var number = parseFloat(prompt('Enter number:'));
    var rounded = Math.round(number);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a quick question about the difference between the 32 and 64 bit
Just a quick question. Is there any performance difference between using PDO::fetchAll() and PDO::fetch()
Just a quick question as to the difference between xpath's 'not' and '!=' in
I have a quick question..is there any difference in these: struct myinnerstruct { int
I have quick question for you SQL gurus. I have existing tables without primary
I have a quick question about fetching results from a weakly typed cursor and
I have a quick question about encapsulating specific types with typedef . Say I
I have a quick question regarding debug and release in VS 2008. I have
I just have a quick question about how to get the length of a
I am somewhat new to LINQ and have a quick question regarding deleting. Say,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.