Math.floor(newton) - Optional Exercise (Working With Negative Values)

On the optional exercise we are asked to convert kelvin to newton. One thing I found interesting about this, and others might have noticed this as well. On the math floor it results to (-91) and if we remove the math.floor we get (-90.09) — So logically I was thinking… shouldn’t this be (-90).

So of course I tested further. I said ok, we are working with a negative value. Let’s inverse this.
Using .33 because I’m lazy. Using value times (-1) to inverse the result.
let newton = (celsius * .33 * (-1)) ;

Sure enough, that was what I expected. Long story short. When working with negative values, the largest integer less than or equal to the given number — in this case (-90.09) does indeed round off to (-91) because (-91) is less than (-90) — which seems confusing to some.

Post was made to help someone in future.

1 Like