Manikandan Ram Manikandan Ram - 3 months ago 14
Javascript Question

How to convert price format string into number in jquery

I have a string like this


"$2,099,585.43"


"$" maybe any symbol, like @,#..etc.

I want to convert this into 2099585.43

Is there any simple way to do this?

Answer

Use String#replace and remove characters which are not a digit or dot.

console.log(
  "$2,099,585.43".replace(/[^\d.]/g, '')
)

Comments