Implement Number.toFixed#1413
Conversation
Perryvw
left a comment
There was a problem hiding this comment.
I'm not sure what the 'simple' behavior vs the rounding behavior is, but this looks alright to me
src/lualib/NumberToFixed.ts
Outdated
| return this.toString(); | ||
| } | ||
| const f = Math.floor(fractionDigits ?? 0); | ||
| if (f < 0 || f > 100) { |
There was a problem hiding this comment.
Actually it may make sence to limit the fraction on ~98 to avoid "invalid format (width or precision too long)"
There was a problem hiding this comment.
Or limit values to <1e19
There was a problem hiding this comment.
I don't really care, even leaving out the check would be an option. Do what you think is best.
| const f = Math.floor(fractionDigits ?? 0); | ||
| // reduced to 99 as string.format only supports 2-digit numbers | ||
| if (f < 0 || f > 99) { | ||
| throw "toFixed() digits argument must be between 0 and 99"; |
There was a problem hiding this comment.
Should errors be exaclty like in JS (between 0 and 100) or this is fine?
Nevermind, I've missed that __TS__NumberToString uses |
Needs some throughts on if
Number.toFixedhas to follow JS rounding behaviour vs having simple implementation and possibly being more fastOtherwise seems to work fine