Created
May 31, 2022 07:07
-
-
Save justxor/4f7df3340b0dfa155e80564df975a0cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var numObj = 5.123456; | |
console.log(numObj.toPrecision()); // выведет '5.123456' | |
console.log(numObj.toPrecision(5)); // выведет '5.1235' | |
console.log(numObj.toPrecision(2)); // выведет '5.1' | |
console.log(numObj.toPrecision(1)); // выведет '5' | |
numObj = 0.000123; | |
console.log(numObj.toPrecision()); // выведет '0.000123' | |
console.log(numObj.toPrecision(5)); // выведет '0.00012300' | |
console.log(numObj.toPrecision(2)); // выведет '0.00012' | |
console.log(numObj.toPrecision(1)); // выведет '0.0001' | |
// Обратите внимание, что если заданного количества разрядов | |
// недостаточно для точного отображения целой части числа, | |
// значение может быть возвращено в экспоненциальной записи. | |
console.log((1234.5).toPrecision(2)); // выведет '1.2e+3' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment