There is a number. For example 0.66111
How to get js - 0.6 ?
function cut(value, precision){ var dec = Math.pow(10, precision) return Math[(value > 0) ? 'floor' : 'ceil'](value * dec) / dec }
For your case just apply a cut(0.66111, 1)
PS I want to note that I wrote the function of circumcision of a number, but not its rounding
UPD. Given the @VladD remark, the function has been improved for use with negative numbers.
.toFixed(precision)
Andrey, in your case .toFixed(precision)
redundant - Specter-0.66111
. ( hint ) - VladDSource: https://ru.stackoverflow.com/questions/168332/
All Articles