Reputation: 1887
I want to split this string:
120,00 m²
into this:
120 m²
I try it with this code:
var test = jQuery('#wpsight-listing-details-3 .span4:nth-child(4) .listing-details-value').html();
var partsOfStr = test.split(',');
alert(partsOfStr);
The alert returns everytime the 'old' string (120,00 m²).
Can somebody helps me?
Thank you very much!
Upvotes: 1
Views: 70
Reputation: 19571
I would use a regular expression and replace, .replace(/,\d+ m²/, ' m²')
like this:
$('.test').text('120,00 m²'.replace(/,\d+ m²/, ' m²'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="test"></div>
Upvotes: 1
Reputation: 20014
Another option that covers different numbers after the comma:
var result= "120,00 m²".replace(/[,]\d+[ ]/,' ');
Upvotes: 1
Reputation: 74738
You can do this:
var test = "120,00 m²";
var partsOfStr = test.split(',00').join('');
alert(partsOfStr);
Upvotes: 1