diff options
author | Roman Reiss <me@silverwind.io> | 2016-12-16 21:20:15 +0100 |
---|---|---|
committer | Roman Reiss <me@silverwind.io> | 2017-03-29 07:12:05 +0200 |
commit | a46c43d21a6c9980c5c1cdafc21be7c96dec1ad5 (patch) | |
tree | adc03f699a16dac8a16f39c5bbe051d423f48ccb /lib | |
parent | 1fde98bb4fa5cab0d060994768ebd055ce6fbf2c (diff) | |
download | android-node-v8-a46c43d21a6c9980c5c1cdafc21be7c96dec1ad5.tar.gz android-node-v8-a46c43d21a6c9980c5c1cdafc21be7c96dec1ad5.tar.bz2 android-node-v8-a46c43d21a6c9980c5c1cdafc21be7c96dec1ad5.zip |
util: add %i and %f formatting specifiers
This change brings formatting specifiers available in `util.format` and
consequently, `console.*` closer to what is supported in all major
browsers.
- `%i` is introduced to format integer values.
- `%f` is introduced to format floating point values.
Fixes: https://github.com/nodejs/node/issues/10292
PR-URL: https://github.com/nodejs/node/pull/10308
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/util.js b/lib/util.js index fa750d363b..8567f8dbaa 100644 --- a/lib/util.js +++ b/lib/util.js @@ -86,6 +86,22 @@ exports.format = function(f) { str += Number(arguments[a++]); lastPos = i = i + 2; continue; + case 105: // 'i' + if (a >= argLen) + break; + if (lastPos < i) + str += f.slice(lastPos, i); + str += parseInt(arguments[a++]); + lastPos = i = i + 2; + continue; + case 102: // 'f' + if (a >= argLen) + break; + if (lastPos < i) + str += f.slice(lastPos, i); + str += parseFloat(arguments[a++]); + lastPos = i = i + 2; + continue; case 106: // 'j' if (a >= argLen) break; |