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

  • Home
  • SEARCH
  • 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 282791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:19:07+00:00 2026-05-12T05:19:07+00:00

The code is: function roundAmount(theDecimal) { var s = + Math.round(theDecimal * 100) /

  • 0

The code is:

  function roundAmount(theDecimal) { 
    var s = "" + Math.round(theDecimal * 100) / 100 
    var i = s.indexOf('.') 
    if (i < 0) { 
        return s + ".00" 
    } 
    var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3) 
    if (i + 2 == s.length)     
        t += "0" 
    return t 
  }

The line with the error:

if (i < 0) return s + ".00"

The error is:

error: expected (;)

does anyone know how to fix this?

  • 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-12T05:19:08+00:00Added an answer on May 12, 2026 at 5:19 am

    About your script:

    The problem in the script above is that last if statement which does some operations followed by a return. You need a semi-colon after the operation.

    In the future, as good practice, make sure to put a semi-colon after every valid statement. That way this won’t bother you.

    Think of each line as a thought, and curly braces as ways to “group” and “relate” thoughts together.

    The below is a full thought that says “give me a variable “i” and give it the value 1 + 2;

    var i = 1 + 2;
    

    The below is a full thought about a condition that says “If i is 3 then add 1 to i”. The thought “add 1 to i” is its own thought, so it needs a semicolon. Since the curlybraces for the IF statement are special in that they don’t need a semi-colon after their “full thought” as long as you put a “block” (which is what curlybraces really make) after it, to enclose the thought.

    This means the following is valid:

    if( i == 3 ) {
        i = i + 1;
    }
    

    The following is not valid because the semi-colon after the if ends the “thought” before the if knows what to do if i equals 3:

    if( i == 3 ) ; {
        i = i + 1;
    }
    

    For a basic JavaScript tutorial, check out W3Schools.

    “There must be a better way?”

    Any time you find yourself doing a lot of string operations on decmials, it’s a good idea to ask yourself “is there a better way to do this?”.

    It looks like you’re writing a function to round a number to the nearest hundredths while displaying two decimal points. There’s a much easier way to do this. You can just round to the nearest hundredths and have javascript output the fixed point number.

    Example:

    function roundAmount( theDecimal ) {
        //first round to the nearest hundredth
        //then return the value with two decimal places as a string
        return theDecimal.toFixed( 2 );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 169k
  • Answers 169k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The totally simple one liner: NSSet *uniqueStates = [NSSet setWithArray:[myArrayOfCustomObjects… May 12, 2026 at 1:57 pm
  • Editorial Team
    Editorial Team added an answer Assuming you are using a UINavigationController, it is added to… May 12, 2026 at 1:57 pm
  • Editorial Team
    Editorial Team added an answer Javascript is single-threaded. If you set a timer that expires… May 12, 2026 at 1:57 pm

Related Questions

I added a google map with two markers (i am just testing), the code
I have a JS function that polls for the current url in an iframe,
I was reading through the source code for MeioUpload to make sure I understand
I'm making a bookmarklet which will load jQuery if the object is not found.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.