Currently, I am in the process of learning Regex and experimenting with it. One thing I'm working on is creating a function that parses a float number while limiting the number of decimal places. My goal is to only allow a maximum of two decimal points, and remove any unnecessary zeros after the decimal (e.g. changing X.00 to just X). Here's the code snippet I have:
price_var.toFixed(2).replace(/0{0,2}$/, "");
Although this code effectively removes the extra zeros, it does not eliminate the decimal point when there are no fractions. Is there a method to achieve this as well?