How to round the value to the nearest whole number?

Tell us what’s happening:
I want to round the value to the nearest whole number.

I have input 2377396.9654660705
Output have to be - 2377399

I can’t understand how to we have to get 2377399

Your code so far


function orbitalPeriod(arr) {
var GM = 398600.4418;
var earthRadius = 6367.4447;

var newArray = [];
for (let i = 0; i < arr.length; i++) {
  var avgAlt = arr[i].avgAlt;
  var r = earthRadius + avgAlt;

  var orbitalPeriod = (2 * 3.14159 * Math.sqrt(r * r * r / GM));

  newArray.push({ 'name': arr[i].name, 'orbitalPeriod': orbitalPeriod});
}

return newArray;
}

console.log(orbitalPeriod([{ name: "iss", avgAlt: 413.6 }, { name: "hubble", avgAlt: 556.7 }, { name: "moon", avgAlt: 378632.553 }]));

Challenge: Map the Debris

Link to the challenge:

parseInt was introduced in the curriculum

but there are also Math.floor, Math.round and Math.ceil, which where also mentioned somewhere

Sorry, but we when do this parseInt(2377396.9654660705) We get output 2377396, but we want 2377399

you can`t get an ending with 9 at all from that number, or 6 or 7 depending on which method you use to round

1 Like

Then, how to we have to get 2377399 in challenge?
With input 413.6 and 556.7 I get correct number but with 2377399 I can’t figure out

what’s this?

which test is failing?

1 Like

Yes, this is test and above my code

orbitalPeriod([
{name: “iss”, avgAlt: 413.6},
{name: “hubble”, avgAlt: 556.7},
{name: “moon”, avgAlt: 378632.553}
])

could be a precision issue, yor value of PI may be bringing precision down. use Math.PI instead

1 Like

Thank you, that’s help me! :grinning:

the issue is that the max precision in multiplication is given by the number with the lowest amount of cifres, with that case, the PI value had a lower number of cifres than the input number

Kindly wrap the output with Math.ceil() , i think that should solve the problem