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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:18:40+00:00 2026-05-23T21:18:40+00:00

I have problems to calculate price with jquery in various price formats (depending on

  • 0

I have problems to calculate price with jquery in various price formats (depending on the language).

With German: 1.375,50 € (Returns 1.38 €)
English format: €1,375.50 (don't work)
French format: 1 375,50 € (Returns 1.00 €)
Italian format: €1,375.50 (don't work)
Spanish format: € 1.375,50 (don't work)

Here is a link of my working demo : http://jsfiddle.net/QmTNZ/63/

And here is my code :

function ca(){
    var $overall = 0;

    $("tr.sum").each(function() {

        var $qnt = $(this).find(".qty");
        var $price = $(this).find("td").eq(2);

        console.log($qnt + " | " + $price);

        var sum = parseFloat($price.text().replace(",", ".")) * parseFloat($qnt.val().replace(",", "."));

        if(isNaN(sum)) {
            sum = 0;
        }
        $(this).find("td").eq(3).text(Math.round(sum * 100) / 100);

        $overall += sum;

    });

    $("#total").text($overall);
}

$(function() {

    ca();
    $('input.qty').bind('change keyup',function(){ca();});

});

The price “td” can contain other texts, for example “Incl. 19% tax”.

My questions here is how can I use a css class that englobe only the price, without the Euro Symbol, to use it in calculation, and how can I avoid the problems of the dot and comma in price calculation in all price formats.

(I’m always beginner in jquery….)

Thanks for help !

  • 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-23T21:18:42+00:00Added an answer on May 23, 2026 at 9:18 pm

    Regardless of anything else, your code is going to have to know the formatting rules for the locale, otherwise you won’t be able to correctly format your resulting sum.

    However, you can avoid worrying about the locale differences in the main body of your code by separating out the price data from the price display. One way you can do that is with a data-* attribute on the element containing the price display.

    For instance, let’s suppose your row looks like this currently:

    <tr><td>Widget</td><td>1</td><td>1 375,50 €</td></tr>
    

    There, the 3rd cell contains the price as text with the various formats. Now, when outputting the table, if you include the price as a data-price attribute in a known, specific format, you avoid all this hassle:

    <tr><td>Widget</td><td>1</td><td data-price="1375.5">1 375,50 €</td></tr>
    

    You can then access it via attr("data-price"):

    var thisPrice = parseFloat($(this).find("td:eq(2)").attr("data-price"));
    

    This gets you the prices in a nice reliable way.

    But again, in the end, you’ll need to know the locale rules in order to display $overall in the correct format.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to following problem to solve. I have to calculate the bidding price
I am using JQuery to calculate some totals figures and I have run into
I'm trying to calculate the average net price of a product. I have, in
I have a function that calculate price for a product. I'm not JavaScript developer
I'm trying to calculate TimeSpans between dates. I have no problem with this if
i have problems with a really basic thing. setting properties after instantiation a UIViewController-
I have problems with creating a simple Group-Box-Control via CreateWindowEx. The font-size/-style of its
I have problems with CSS. The table is creating white border and I do
I have problems dealing with ProGuard and Android. I searched on the web for
I have problems trying to load png file into my application. It seems to

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.