refactor number format using Intl.NumberFormat, add parent_element option #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Two motivations:
Calculate/return numbers that can be directly cast as numbers without addition text parsing. The grouping ("thousands") separator is a problem. Using javascript Intl.NumberFormat class as an option allows very fine control of number to string formatting and provides additional options for currency and other locale differences. (as a minor benefit, it also simplifies the current logic that utilizes regex replacements that are somewhat inflexible)
Append to an optional parent_element instead of only $("body"). This allows the ticket to be visible when the input with calculadora is in a modal above the main body. In this case, for me, this creates a bug whereby the alignment is off (the ticket isn't close to the input to appear "attached") but at least it's visible.
I wrote this in a way that I believe is backward-compatible with the current options:
decimalsanduseCommaAsDecimalMark. It could be further simplified to eliminate those options and only use this newnumberFormatoption.I did not create a minified map so that could be done if desired.
My previous pull-request addresses a bug-fix without any change to features or functionality; it would be unnecessary if merging this PR.
I know there haven't been commits to this project for many years. So this may just be a note of appreciation. I am submitting this to share my work in case it would be useful to you or others.
Cheers,
Greg