Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decimalPrecision option and supporting tests #15

Closed
wants to merge 2 commits into from

Conversation

styks1987
Copy link
Contributor

This allows the user to pass a decimalPrecision option and the number will format based on the precision. I know this could be done with the format but it is nice to have working in conjunction with prefix and suffixes.

@@ -24,7 +25,8 @@ const propTypes = {

const defaultProps = {
displayType: 'input',
decimalSeparator: '.'
decimalSeparator: '.',
decimalPrecision: false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep then default value of decimal precision as unlimited

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand your comment. If they pass false to the decimalPrecision, it would be unlimited number of decimal places. Could you explain this a little more?

@@ -139,9 +142,14 @@ class NumberFormat extends React.Component {
}
else{
let beforeDecimal = formattedValue, afterDecimal = '';
const hasDecimals = formattedValue.indexOf(decimalSeparator) !== -1;
const hasDecimals = formattedValue.indexOf(decimalSeparator) !== -1 || decimalPrecision !== false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on current default value of decimalPrecision, user always have to define decimalPrecision otherwise he will not be able to add it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not be able to add what? If they don't define decimalPrecision, it would bypass my change altogether and function as it normally would. Am I missing something?

@bengtrj
Copy link

bengtrj commented Jan 25, 2017

I like the library but the lack of a way to have the decimals always shown is keeping me from using it. The patch is perfect and includes tests, I hope it's incorporated soon!!

@s-yadav
Copy link
Owner

s-yadav commented Jan 27, 2017

@styks1987 Ignore the previous comments. Code looks good. Though there are some fixes required.

  1. Eslint error
  2. If we press backspace just after decimal it corrupt the number, ie $23,498.00 becomes $23,49,800.00

I will see what I can do fo this in this weekend.

s-yadav added a commit that referenced this pull request Feb 2, 2017
- Fixed #21
- Implemented #18
@s-yadav s-yadav added this to the 1.1.0 milestone Feb 3, 2017
@s-yadav s-yadav closed this Jul 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants