Luis Valencia
Luis Valencia

Reputation: 34038

Remove Euro Value and money format with JQuery

I already know how to get a value from a label, the problem is that its showing something like

€123,453.28

I need to remove the eurosign and the commas to be able to make a calculation.

Not remove the decimal point of course

$(document).ready(function () {
            $("#TxtVatExcluded").keypress(function () {
                var invoicedAmmount = $("#MainContent_VehicleInformationControl_LblInvoicePriceValue").text();
                alert(invoicedAmmount);
                if (invoicedAmmount > 0) {
                    var ammountWithoutVat = $("#TxtVatExcluded").val();
                    var result = (ammountWithoutVat / invoicedAmmount) * 100;
                    $("#OutputLabel").html(result + " %");
                }
            });
        });

Upvotes: 3

Views: 3972

Answers (1)

gdoron
gdoron

Reputation: 150303

"€123,453.28".replace(/[^\d.]/g,"") // Replace every non digit char or dot char
                                    // With an empty string.

Live DEMO

So in your code:

var ammountWithoutVat = $("#TxtVatExcluded").val().replace(/[^\d.]/g,"");
var result = (pareseFloat(ammountWithoutVat, 10) / invoicedAmmount) * 100;

Upvotes: 6

Related Questions