0

My code:

test = '1.111,111'
test2 = parseFloat(test)
test3 = test.replace(/,/g, '.')
console.log(test2)//1.111
console.log(parseFloat(test3))//1.111

I need the whole number returned as a string in the "test" variable to be returned.

I want the return of: 1.111,111 in number format.

How can I do this?

user229044
  • 232,980
  • 40
  • 330
  • 338

1 Answers1

0

I'll break this into steps for you to understand better:

test = '1.111,111';
test2 = test.split('.').join(''));
test3 = test2.replace(',', '.');
test4 = parseFloat(test3);

You can do this in one line:

test = parseFloat(test.split('.').join('').replace(',', '.'));
panoplied
  • 1
  • 1