I have a jquery function that should make a calculation based on a textbox value.
That textbox has a maskededit extender, by default it shows dollar sign, and the calculation works.
When I add the culturename property it shows the euro sign, but then the calculation stops working and it returns NaN
<ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server"
TargetControlID="TxtVatIncluded"
Mask="9,999,999.99"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Number"
InputDirection="RightToLeft"
DisplayMoney="Left" CultureName="nl-BE"
/>
$(document).ready(function () {
$("#TxtVatExcluded").focusout(function () {
debugger;
var invoicedAmmount = $("#MainContent_VehicleInformationControl_LblInvoicePriceValue").text().replace(/[^\d.]/g, "");
if (invoicedAmmount > 0) {
var ammountWithoutVat = parseFloat($("#TxtVatExcluded").val().replace(/[^\d.]/g, ""));
var result = ((ammountWithoutVat / invoicedAmmount) * 100).toFixed(2);
$("#MainContent_LblPercentage").html(result + " %");
}
});
});
The Globalize javascript library can handle this scenario. Once the library is initialized with the correct language code
Globalize.culture(languageCode);, you can use theGlobalizeversion ofparseFloatwhich handles the different currency symbol and numeric separators. For example,Globalize.parseFloat('€9,99')returns9.99when using the Dutch/Belgium language code.