I am currently trying to make an input that will take in decimal numbers and will auto format with thousand separators at the same time.
However, the only I can do auto format thousand separator is to set input type='text', which I cannot enter decimal numbers. Where as setting input type='number' allows me to input decimal number but it won't auto format with thousand separators
Here is the code:
<input
className="cal__section__form__container--input"
placeholder={0}
type="text"
value={displayVal || ""}
onChange={(e) => {
const targ = e.target.value.replace(/\D/g, "") || 0;
const displayVal = parseFloat(targ).toLocaleString(undefined, {
maximumFractionDigits: 2,
});
console.log(displayVal);
}}
/>