Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

60
Views
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'}
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!