Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

62
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda