How to convert data with k and M at the end back to numbers in json array

I am getting data from an API in jso format but one of the element is giving values in k and M instead of thousand and million.
how can I convert it back to number.

k = [
{
'stock_change_volume' : '169.2 K
'
},
{
'stock_change_volume' : '69.2 K
'
},
{
'stock_change_volume' : '169.2 M
'
}

]

>Solution :

var k = [
{
'stock_change_volume' : '169.2 K'
},
{
'stock_change_volume' : '69.2 K'
},
{
'stock_change_volume' : '169.2 M'
}
];

for(var i of k){
  console.log(getVal(i['stock_change_volume']));
}

function getVal (val) {
  var value = val.substr(-1).toLowerCase();
  if (value == "k")
    return parseFloat(val) * 1000;
  else if (value == "m")
    return parseFloat(val) * 1000000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Leave a Reply