Forum Discussion
Help with Java Script to format numbers
Hi, sorry dont worry I saw that piece of code above did that I hope. I will give it a go.
In a previous slide where the java script works, I use a constant variable numValue = numValue
var player=GetPlayer();
var numValue=player.GetVar("Per1");
var numValue=numValue.toFixed().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$&,');
var txtValue=numValue.toString();
player.SetVar("txtPer1", txtValue);
The user puts in a number for the purchase price of a house and this is stored in numValue. Then that is multipled by Per1 (0.1) and the new Per1 is found e.g. 10 (numValue is 100).
I then want the txtPer1 value of the dollars, to be shown and it does perfectly.
But when I do the same code for this different variable in a different scene, it doesn't work.
var player=GetPlayer();
var numValue=playerGetVar("DepAmt");
var numValue=numValue.toFixed().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$&,');
var txtvalue=numValue.toString();
player.SetVar("txtDepAmt",txtvalue);
var player=GetPlayer();
var numValue1=playerGetVar("DepAmt1");
var numValue1=numValue1.toFixed().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$&,');
var txtvalue1=numValue1.toString();
player.SetVar("txtDepAmt1",txtvalue1);
Am I supposed to be using DepAmt in the lines
var numValue=playerGetVar("DepAmt");
(instead it is DepAmt=playerGetVar("DepAmt")
var numValue=numValue.toFixed().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$&,');
(instead it is DepAmt=DepAmt.toFixed().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$&,');
var txtvalue=numValue.toString();
(instead it is txtvalue=DepAmt.toString()
Sorry I realise this must be pretty straight forward for you but I am just confused as to why it works perfectly in one set of slides and not at all in another.
Cheers
Kim
Related Content
- 10 months ago
- 8 months ago
- 5 months ago
- 2 months ago