JSFiddle - React, Tailwind, and code Playground
JavaScript
let value = '123.456,79'; //123,457
function isNumeric(str) {
if (typeof str !== 'string') {
return false;
}
return (
!isNaN(str) &&
!isNaN(parseFloat(str))
);
}
const valueToStore = value.replace(',', '.').replace(' ', '');
const valid = isNumeric(valueToStore);
if (valid) {
const result = Math.round((parseFloat(valueToStore) + Number.EPSILON) * 100) / 100;
console.log(result);
} else {
console.log('not valid');
}