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 8899175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:47:46+00:00 2026-06-15T00:47:46+00:00

I have a javascript / jquery code that takes in a formula and numbers

  • 0

I have a javascript / jquery code that takes in a formula and numbers from the user and solves the equation. My code in jquery can get the solution down to real numbers, but in the form of a string and I can’t get javascript to solve the equation mathematically.

I have something like

1000 * (200+3928)/2333

However, those numbers are all in string format and forcing each of them into floats or integers and reinserting them only turns them back into a string. Tried using valueOf and other things, but nothing works. Is there a better way or something I am missing?

Thanks

  • 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-06-15T00:47:48+00:00Added an answer on June 15, 2026 at 12:47 am

    When you have a simple equation in the form of a string, the most practical method is to parse the string into prefix or postfix notation, then evaluate it accordingly…

    Assuming the original string is infix (the notation humans use to learn basic math) such as…

    1000 * (200+3928)/2333

    You then convert it to postfix to obtain…

    1000, 200, 3928, +, *, 2333, /

    Using this notation, a computer can easily evaluate the expression using a simple loop and stack…

    I wont post actual code, because I want to leave the fun parts up to you, but if you’d like a headstart with psuedo code, here goes…

    infix to postfix :
    
      create empty array `postfix` and `temp`
    
      split the expression up into an array `A` by each operand/operator
    
      foreach token in `A`:
        if char is operand :
          push to postfix stack
        if char is open parenthesis:
          push to temp stack
        if char is close parenthesis:
          while top of temp stack != '(' :
            push top of temp stack to postfix stack
            pop top of temp stack
          end while
          pop top of temp stack
        if char is operator:
          while temp stack isn't empty *and* top of temp stack != '(' *and* precendence(char) <= precendence(top of temp stack) :
            push top of temp stack to postfix stack
            pop top of temp stack
          end while
          push char to temp stack
    
      end for loop
    
      while temp stack is not empty
        push top of temp stack to postfix stack
        pop top of temp stack
      end while
    
      return postfix stack (will be your postfix stack to evaluate)
    
    
    
    evaluate postfix stack:
      create array A
      foreach token in postfix stack:
        if char is operand:
          push to A stack
        if char is operator:
          int x = pop A stack
          int y = pop A stack
          result = x (operation) y
          push result to A stack
      end for loop
    
      return top of A stack (this will be the final result)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bit of javascript/jquery code that takes a long string, and sends
I have the following JavaScript/jQuery code that starts the listener that highlights the DOM
I have this javascript code below that uses jquery, it is suppoed to be
I have a jQuery function that takes the value from a PHP-generated check box
I have this code that takes info from a form and sends it to
I have some jQuery AJAX code that takes the contents of a text-area and
I have this Javascript/JQuery code: <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js></script> <script type=text/javascript> name = $(#name).val(); alert(Name:
I have a very simple JavaScript/jquery code which won't just work correctly. The problem
I have problems with the following bit of javascript/jquery code: this.droppable = function(){ $('.imageWindow
I have the following Javascript code (using jQuery): floatUpAndDown(); function floatUpAndDown() { $(#bird).animate({top: '+=30px'},

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.