Most appropriate sub-area of p5.js?
Utilities
p5.js version
2.x main (4b096e2)
Actual vs expected behavior
nfc()'s own reference examples document rounding and zero padding, but doNfc in src/utilities/utility_functions.js compares the requested decimal count against a substring that still contains the leading ., so it truncates where the docs round and skips the padding branch by one:
nfc(12345.67, 1); // actual '12,345.6' documented '12,345.7'
nfc(12345.67, 3); // actual '12,345.67' documented '12,345.670'
nf() already rounds via toFixed, so the two formatters also disagree with each other on the same input. A rounding carry also needs comma re-grouping, e.g. nfc(999.96, 1) should give '1,000.0'.
Steps to reproduce
Outputs above are from executed runs against current main via the unit test harness (npx vitest run test/unit/utilities/utility_functions.js with added cases).
Note
I have a fix ready (route through toFixed like nf, keep the comma grouping, preserve the existing nfc(32000, '3') === '32,000.000' behavior) with unit tests covering rounding, padding, the carry re-group and negatives. Verified the four new tests fail on current main and pass with the change, 23 existing tests unaffected. Filing for approval first per the contributing guide; will open the PR once approved.
Most appropriate sub-area of p5.js?
Utilities
p5.js version
2.x main (4b096e2)
Actual vs expected behavior
nfc()'s own reference examples document rounding and zero padding, butdoNfcinsrc/utilities/utility_functions.jscompares the requested decimal count against a substring that still contains the leading., so it truncates where the docs round and skips the padding branch by one:nf()already rounds viatoFixed, so the two formatters also disagree with each other on the same input. A rounding carry also needs comma re-grouping, e.g.nfc(999.96, 1)should give'1,000.0'.Steps to reproduce
Outputs above are from executed runs against current main via the unit test harness (
npx vitest run test/unit/utilities/utility_functions.jswith added cases).Note
I have a fix ready (route through
toFixedlikenf, keep the comma grouping, preserve the existingnfc(32000, '3') === '32,000.000'behavior) with unit tests covering rounding, padding, the carry re-group and negatives. Verified the four new tests fail on current main and pass with the change, 23 existing tests unaffected. Filing for approval first per the contributing guide; will open the PR once approved.