Math.round() shows the 1675 result, but I wanted it to round to 1700

Asked

Viewed 59 times

0

I’m having trouble with the Math.round() in Javascript, it shows the result 1675, but I wanted him to round up 1700.

var altura = 170
var peso = 70
var idade = 30
var tmb 

tmb = 66.5 + (13.75 * peso) + (5.0 * altura) - (6.8 * idade)

console.log(Math.round(tmb))

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.

1 answer

1

Since apparently you want to round 2 digits in the whole part then you have to make these digits go to decimals, dividing by 100 and then going back to normal by multiplying by 100, that is, pure mathematics.

var altura = 170
var peso = 70
var idade = 30
var tmb = 66.5 + (13.75 * peso) + (5.0 * altura) - (6.8 * idade)
console.log(Math.round(tmb / 100) * 100)

I put in the Github for future reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.