Search code examples
javascriptvisual-studio-lightswitchlightswitch-2013

Javascript - Concat a string and int not working (Lightswitch HTML)


scenario: I have a data item which I want to display the total of a value. and this is done with the following code:

var int1 = 5;
var int2 = 6;
var int3 = 7;
var total = parseFloat(int1) + parseFloat(int2) + parseFloat(int3);
//total = 18.00;

Now this displays as 18 on the screen where I want it to appear however I am having difficulty in adding a £ symbol to the equation. I've tried the following with little success:

var displayTotal = "£" + total  //returns NaN

var symbol = "£";
var changeToString = total.toString();
var displayTotal = symbol.concat(changeToString); //retuns NaN

this isn't that difficult so im missing something obvious so hopefully I can get the help I need here. and to clarify I want to be able to display my Total with a £ sign in front, i.e. £18.00

thanks for any help


Solution

  • Use the "\u00A3" code for the pound symbol. It should look like example below:

    var displayTotal = "\u00A3" + total;