const text = "Hello team, I checked my wallet balance, there is 0,0000341 USDT, I can not buy anything";
Need to get a number using only one loop for and charCodeAt()
const parseBalance = (str) => {
const zero = "0".charCodeAt(0);
const nine = "9".charCodeAt(0);
const coma = ",".charCodeAt(0);
let num = 0,
factor = 1;
for (let i = str.length - 1; i >= 0; i--) {
const char = str.charCodeAt(i);
if (char >= zero && char <= nine) {
num += (char - 48) * factor;
factor *= 10;
}
}
return num;
};
Need result: 0.0000341
My result is 341
Tell me how to correct the formula for writing zeros