The following code in node 6.10.3 prints percent: 10%, fraction: 0.1
console.log('percent: %d%, fraction: %d', 10, 0.1);
In node 8.1.0 it prints percent: 10 fraction: 0.1. Notice the % is no longer printed.
The following code gets back to the original node 6.10.3 output
console.log('percent: %d%%, fraction: %d', 10, 0.1);
Note the %% to print a single % in node 8
Also worth noting this problem doesn't happen if you are just printing one variable in node 8. The following code prints percent: 10%
console.log('percent: %d%', 10);
Should node 8 be formatting the same results as node 6? Or is this a functional change?
This is probably due to https://github.com/nodejs/node/pull/12407.
/cc @nodejs/ctc
/cc @jseijas
Possible fix: https://github.com/nodejs/node/pull/13674
Ideally we should throw an error in such cases. The correct format string here is 'percent: %d%%, fraction: %d'.
Yes, a throw would be ideal, but from my tests browsers don't throw on it either, so It'd be better to not throw for compat. I tested the case console.log('percent: %d%, fraction: %d', 10, 0.1); in a few browsers:
Firefox: percent: 10%, fraction: 0
Chrome: percent: 10%, fraction: 0
Safari: percent: 10[object Object] fraction: %6d
Quite an interesting result in Safari (also present in WebKit Nightly).
I can confirm the correct format of console.log('percent: %d%%, fraction: %d', 10, 0.1); gives the desired output of percent: 10%, fraction: 0.1 in Node 6.10.3 and 0.10.48
Most helpful comment
Ideally we should throw an error in such cases. The correct format string here is
'percent: %d%%, fraction: %d'.