Если вы хотите манипулировать в десятичном формате, иногда лучший способ - просто обработать его как строку десятичных цифр.
function oneSignificantDigitAwayFromZero(n) {
// Convert to a string of digits.
var s = "" + n;
// This regexp grabs any sign, and leading zeros in one group,
// the digit to promote in another, and the trailing digits in a third.
// This regexp is guaranteed not to accidentally grab any exponent.
return s.replace(/^(-?[0.]*)([1-9])([0-9.]+)/, function (_, before, digit, after) {
// Round the digit up if there is a non-zero digit after it,
// so 201 -> 300, but 200 -> 200.
var roundUp = /[1-9]/.test(after) ? +digit + 1 : +digit;
// Replace all non-zero digits after the one we promote with zero.
// If s is "201", then after is "01" before this and "00" after.
after = after.replace(/[1-9]/g, "0");
// If roundUp has no carry, then the result is simple.
if (roundUp < 10) { return before + roundUp + after; }
// Otherwise, we might have to put a dot between the 1 and 0 or consume a zero from
// the fraction part to avoid accidentally dividing by 10.
return before.replace(/0?([.])?$/, "1$10") + after;
});
}