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

79
Views
el procesamiento de números decimales falla

Estoy tratando de comparar los números con otro número y luego clasificarlo en una zona climática, pero surge el siguiente problema

Obtengo datos a través de un archivo JSON en el que también hay números decimales con un punto decimal, por lo que mi código JavaScript debería procesarlos fácilmente, pero si trato de usar esto, aparece undefined o NaN , incluso si solo intento registrar el número alguien me puede ayudar?

El archivo JSON:

 { "tabel": [ { "january": { "temperature": 6.9, "precipitation": 76 }, "February": { "temperature": 7.7, "precipitation": 88 }, "March": { "temperature": 10.8, "precipitation": 77 }, "april": { "temperature": 13.9, "precipitation": 72 }, "May": { "temperature": 18.1, "precipitation": 63 }, "June": { "temperature": 22.1, "precipitation": 48 }, "July": { "temperature": 24.7, "precipitation": 14 }, "August": { "temperature": 24.5, "precipitation": 22 }, "september": { "temperature": 21.1, "precipitation": 70 }, "October": { "temperature": 16.4, "precipitation": 128 }, "November": { "temperature": 11.7, "precipitation": 116 }, "December": { "temperature": 8.5, "precipitation": 106 }, "annual_average": { "tempertur": 15.5, "precipitation": 880 } } ] }

Mi código:

 const data = require("./data.json"); let k2; let k3; let humid = 0; let k1; if (data.tabel[0].annual_average.precipitation < 250) { k1 = "B"; } else if (data.tabel[0].annual_average.temperature > 15) { k1 = "A"; } else if (data.tabel[0].annual_average.temperature > 12) { k1 = "C"; } else if (data.tabel[0].annual_average.temperature > 0) { k1 = "D"; } else if (data.tabel[0].annual_average.temperature > -10) { k1 = "E"; } else if (data.tabel[0].annual_average.temperature < -10) { k1 = "F"; } console.log(k1);

El código de salida: undefined

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tienes un error tipográfico en el nombre del campo

 "annual_average": { "tempertur": 15.5, "precipitation": 880 }

"temperatur" en lugar de "temperature"

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!