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
Conversation
@@ -24,7 +25,8 @@ const propTypes = { | |||
|
|||
const defaultProps = { | |||
displayType: 'input', | |||
decimalSeparator: '.' | |||
decimalSeparator: '.', | |||
decimalPrecision: false |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
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!! |
@styks1987 Ignore the previous comments. Code looks good. Though there are some fixes required.
I will see what I can do fo this in this weekend. |
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.