Methods to convert Currency String to a Double value

Table of Content

  • Method 1: Using str.charCodeAt() and substring() method
  • Method 2: Using JavaScript replace and parseFloat methods
  • Method 3: Using Regular Expression Directly

How to convert a currency string to a double value with jQuery or Javascript?

In this article, we will convert a currency string to a double value with jQuery or Javascript. There are two popular ways to convert currency string into float string using different JavaScript inbuilt libraries. 

Similar Reads

Methods to convert Currency String to a Double value

Table of Content Method 1: Using str.charCodeAt() and substring() method Method 2: Using JavaScript replace and parseFloat methodsMethod 3: Using Regular Expression Directly...

Method 1: Using str.charCodeAt() and substring() method

This is a simple approach in which we will match characters one by one from starting using the loop and if any character comes out to be of integer type or numeric type then we will use the substring() method to take out the substring from the original string. After taking out the substring we will use the parseFloat() method to convert that string to float to a double value. To check whether the character is of numeric type or not, we use charCodeAt() method to get the Unicode value of the specified character....

Method 2: Using JavaScript replace and parseFloat methods

In this method, we will use replace()method of JavaScript to replace every character other than numbers and decimal (.) with blank (“”). After then we can use parseFloat() method to make the string float or double. This method is more efficient than method 1....

Method 3: Using Regular Expression Directly

This approach directly employs a regular expression to match numeric and decimal characters in the currency string. It then extracts these characters, joins them to form a numeric string, and converts it to a double value using parseFloat()....

Contact Us