indexOf is not a function

indexOf() is a method of Strings, not Numbers.

console.log( TotalAccountBalance.toString().indexOf('.') );

TotalAccountBalance = +CurrentPreservedBalance + +CurrentGeneralAccountBalance;

The unary plus operators convert the strings into numbers; this is obviously desirable behaviour in order to get the correct mathematical result.

If you then want to use a string function (e.g. indexOf), you need to convert back to a string:

console.log( ("" + TotalAccountBalance).indexOf('.') );

TotalAccountBalance = +CurrentPreservedBalance + +CurrentGeneralAccountBalance;

TotalAccountBalance is the result of taking two numbers (we know they are numbers because you used the unary plus operator to convert them) and adding them together. This is another number.

indexOf is a method that you find on strings not numbers.

You could convert to a string:

(TotalAccountBalance + "").indexOf('.')

Tags:

Javascript