What is the JS regular expression when the pattern must match the first occurrence of ".x", where x can be any digit and . means the decimal point.?
E.g., salary = "5200.2" (it is first defined as a number but then after a few modifications in the lines that follow, it becomes a string before entering the if statement, which is when I am using regular expressions to look for the occurrence of ".x"
var salary =5200.2;
salary = salary.toFixed(2); //string
salary = parseFloat(salary);
salary = salary.toLocaleString();
if (!salary.includes('.')){
salary = salary + ".00"
}else if (salary.includes("/[.[0-9]]/") && salary.charAt(salary.length) == ""){
salary = salary + '0';
}
I need help with the salary.includes("/[.[0-9]]/") && part. Regular expression pattern must be ".0"
What my code sample is trying to accomplish is, if my number is 5200.0 or 5200 it will make it 5,200.00 for both.