lampstand
lampstand

Reputation: 111

extracting numbers from string and removing the decimals and add it to the string back

I have a string ="this is test 12.00 and 15.00". My requirement is to remove the decimals from the string .

My output should be "this is test 12 and 15". I have tried splitting the string and remove the decimals and replacing it however not working right. can some expert advise on this please.

Upvotes: 1

Views: 31

Answers (1)

Gerardo BLANCO
Gerardo BLANCO

Reputation: 5648

You could use the next regexp /\.\d{0,}/g And with the replacefunction, you delete the decimal numbers.

Hope this helps :>

let str ="this is test 12.00 and 15.00"
console.log(str.replace(/\.\d{0,}/g,''))

Upvotes: 2

Related Questions