I am looking for a regex to mark all zeros from the right until it faces a non zero.
For example,
5819323.0100-
the regex should detect that it exists two zero from the right and it should start to validate after the .
.
I am looking for a regex to mark all zeros from the right until it faces a non zero.
For example,
5819323.0100-
the regex should detect that it exists two zero from the right and it should start to validate after the .
.
I don't believe you meant to keep that dash at the end…
Use a positive lookbehind of (?<=\.\d*)
and end the expression with an end of line i.e. $
. The look behind checks for a sequence of zeros at the end of the string that are preceded by a decimal point and zero or more digits.
const
input = '5819323.0100',
output = input.replace(/(?<=\.\d*)0+$/, '');
console.log(output); // 5819323.01
If you are using this as a number, just parse it; the zeroes will be ignored.
const
input = '5819323.0100',
output = parseFloat(input);
console.log(output); // 5819323.01