geo _
geo _

Reputation: 29

How to bring only price value which with text and curreny symbol?

Now I have NT$ symbol in price, so i want to remove it so i can bring the only price(number) into script to future calculate. what should I change?

var test = document.querySelector(".origprice");
var price = parseInt(fparent.textContent.replace(/NT/,/\U+00024/,/,/,''));
var testt = price - 150;

document.getElementById("demo").innerHTML = testt;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

<div id="test">
<table id="table">

  <tr>
     <td class="origprice">NT$ 1,500</td>
  </tr>

</table>

<p id="demo"></p>

</div>

Upvotes: 0

Views: 45

Answers (2)

Sivakumar
Sivakumar

Reputation: 347

If you will have space between prices and $, then you can do like the below,

$(document).ready(function(){
    let total = 0;
  $('.origprice').each(function() {
    total += Number($(this).text().split(' ')[1]);
  });
  console.log(total);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
  <td class="origprice">NS$ 10000</td>
  <td class="origprice">NS$ 20000</td>
  <td class="origprice">NS$ 30000</td>
</tr>
</table>

Upvotes: 1

ME-ON1
ME-ON1

Reputation: 83

you can use this function to get the desired result.

var txt="NT$ 1,500";
let t= ""
var numb = txt.match(/\d/g).map(i => {
 t += i ;
})


console.log(+t);

Upvotes: 1

Related Questions