Reputation: 985
I am reading numbers in financial #s format from cells. 5,000 is financialNumberOne and 3,000 is financialNumberTwo;
var financialNumberOne = ss.getRange("A1").getDisplayValue();
var financialNumberTwo = ss.getRange("A2").getDisplayValue();
How can I convert this into number so that I can do some math with it?
var result = financialNumberOne + financialNumberTwo;
Following did not work.
var result = +financialNumberOne + +financialNumberTwo;
Number(financialNumberOne);
//It is reading NaN
parseInt(financialNumberOne);
//It is reading 5,000 as 5
Upvotes: 0
Views: 170
Reputation: 663
You should use getValue()
instead of getDisplayValue()
because getDisplayValue()
will just get a string like "5,000.00"
. So the correct code for getting the numbers would be something like this.
var financialNumberOne = ss.getRange("A1").getValue();
var financialNumberTwo = ss.getRange("A2").getValue();
Upvotes: 1