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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:41:44+00:00 2026-06-14T23:41:44+00:00

Possible Duplicate: Is JavaScript’s Math broken? from this question: get all the input value

  • 0

Possible Duplicate:
Is JavaScript’s Math broken?

from this question:
get all the input value and make an addition

there is a promotion:

buy 1 each price is 14.37, buy 10 the price is 13.28, buy 20 each price is 10.78…..

now i want to do a counter.http://down123.xxmn.com/count.htm

the counter write the whole price.now, there is something wrong with my code.

if i fill 5 in an input box, then fill 5 in another input box. the whole price isn’t 132.8. why?

if i remove a number in an input box, the whole price doesn’t change. thank you

the code:

var $inputs = jQuery('.liste_couleur_qty li input');
$inputs.keyup(function() {
   var result = 0;
   $inputs.each(function(){
     result += parseInt(this.value, 10);
   });
   var JsonData =[{"price_id":"1","website_id":"0","price_qty":1,"price":"14.37"},
 {"price_id":"2","website_id":"0","price_qty":10,"price":"13.28"},
 {"price_id":"3","website_id":"0","price_qty":20,"price":"10.78"}, 
  {"price_id":"3","website_id":"0","price_qty":50,"price":"9.23"},
   {"price_id":"3","website_id":"0","price_qty":100,"price":"7.91"}
 ]
   var sorted = JsonData.sort(function(a,b){return a.price_qty - b.price_qty;});

var i=0;
while(i < sorted.length && sorted[i].price_qty <= result){i++;} 

var price = sorted[i-1].price;

   price= price*result;

   jQuery('#qtyvalue').html("Total price is " + price);    
});

now, when the qty is 9, the right price is 9*14.37. but my counter is not right.

  • 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-14T23:41:46+00:00Added an answer on June 14, 2026 at 11:41 pm

    The answer you are looking for is a method called .toFixed()

    Try changing the last line that sets your price to

    jQuery('#qtyvalue').html("Total price is " + price.toFixed(2));
    

    and that should work.


    Update:

    When you empty any text box, your code stops working since the value is '' rather than 0, and can’t be added. Update the 5th line of the code to this:

    result += parseInt((this.value === '' ? 0 : this.value), 10);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Is JavaScript’s math broken? This seems really stupid, but when running this,
Possible Duplicate: Is JavaScript's Math broken? I came across this rounding issue: When I
Possible Duplicate: Is JavaScript's Math broken? Strange result with floating point addition Some simple
Possible Duplicate: Is JavaScript’s Math broken? Funny question, but why at 16.1 javascript become
Possible Duplicate: Is JavaScript's Math broken? I'm attempting to add up three input fields,
Possible Duplicate: Strange javascript addition problem I know there's obviously a solution for this,
Possible Duplicate: Is JavaScript's Math broken? Adding fractions number yields different result in PHP
Possible Duplicate: Is JavaScript's Math broken? Any ideas as to why: (872.23 + 2315.66
Possible Duplicate: Is JavaScript's Math broken? I have just started playing around with Javascript
Possible Duplicate: Is JavaScript’s Math broken? I'm using Math.round to round the number and

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.