Como usar substring em React Native?
if (total >= 1000){
const total2 = total.substr(total.lenght - 3, total.lenght);
total = total2 + '.' + total.substr(total.lenght - (total.lenght - 1), total.lenght - 3);
}
Erro:
undefined is not a function (evaluating 'total.substr(total.lenght - 3, total.lenght);')
Minha intenção e verificar se o valor é maior ou igual a 1000, dividir a string em duas partes e colocar o ponto na terceira casa de trás pra frente: 1.000
total.toString().substr(total.lenght - 3, total.lenght);
como pode ver, esta convertendo para string pois o métodosubstr
é para string. String.prototype.substr()