Add Text Strings together with parseFloat returns NaN

Hi,

I have searched this forum but having a problem adding text strings together to sum them together and get a total.

so I am using:

var a = parseFloat($w(“#text1”).value);
var b = parseFloat($w(“#text2”).value)

var totalprice = a + b
$w(“#totalprice”).value = totalprice;
}

the text1 and text2 value are currency strings using .toLocaleString(‘en’, { style: ‘currency’, currency: ‘GBP’ })

If I change code to:

var a = $w(“#text1”).value;
var b = $w(“#text2”).value;
var totalprice = a + b
$w(“#totalprice”).value = totalprice;
}

I get them adding as strings like £100£200 etc

Any ideas?

Thanks

You cannot add text values with a sybmol or text in it. Even if you use a number wrapper its not gonna work. Try this:

var a = $w("#text1").text;
var b = $w("#text2").text;
var x = a.slice(1); //remove the symbol
var y = b.slice(1); //remove the symbol
var totalprice = Number(x) + Number(y);
$w("#totalprice").value = totalprice.toLocaleString('en', { style: 'currency', currency: 'GBP' });

thank you so much

This works perfectly. If I have this kind of text string and I want to push it to a connected database, will that work? I have the connected the text box to the database, with a submit button etc but everything but the price data in the format £#### will get populated in the database.

In this because its a non-user input field or because of the text string issue?

thank you.