Convert String with Dot or Comma as decimal separator to number in JavaScript

Andrus :

An input element contains numbers a where comma or dot is used as decimal separator and space may be used to group thousands like this:

'1,2'
'110 000,23'
'100 1.23'

How would one convert them to a float number in the browser using JavaScript?

jQuery and jQuery UI are used. Number(string) returns NaN and parseFloat() stops on first space or comma.

hytest :

Do a replace first:

parseFloat(str.replace(',','.').replace(' ',''))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to convert floating point decimal separator from dot to comma in Javascript

formatting decimal number to string with comma as decimal separator in racket

Java Double to String with dot separator and infinite number of digits after the decimal

NumericUpDown: accept both comma and dot as decimal separator

seq uses both comma and dot as a decimal separator

How to make that f"..." string formatting uses comma instead of dot as decimal separator?

New Webkits convert decimal comma to ~ dot and vice versa in number-type inputs. Javascript name of that browser feature?

Convert a double to 2 decimal places with comma separator

Angular uses comma instead of dot as decimal separator after changing culture

How to accept both dot and comma as a decimal separator with WTForms?

How to change the decimal separator of DecimalFormat from comma to dot/point?

Azure Data Factory: Reading doubles with a comma as decimal separator instead of a dot

Parsing numbers with a comma decimal separator in JavaScript

JavaScript regex to accept numbers with comma separator (thousands) and dot separator (decimals)

Convert comma or dot string to single

How to replace decimal separator dot by decimal separator comma in formattable() package R?

jQuery Validation Plugin: validate decimal number with comma as decimal separator

Javascript How to convert a decimal number to a string with specific number of decimal places

Convert negative number in string to negative decimal in JavaScript

Manually Convert A Decimal String To A Number Using JavaScript

Convert Large Decimal Number to String in Javascript

Convert a number and accept any decimal separator

Python regex for number with or without decimals using a dot or comma as separator?

decimal separator in woocommerce to be a comma

Number comma separator for String numbers in Java

Decimal dot and thousands separator used both in input type number

How to convert a number with comma as string into float number in Javascript

Convert string with thousands (and decimal) separator into double

How to format a float with a comma as decimal separator in an f-string?