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

allow a decimal format for an integer #222

Merged

Conversation

mguida22
Copy link
Contributor

From #199, when using a decimal format with a wildcard, on an integer, numbro gives an error

numbro(-40).format('#.*');

numbro.js:643 Uncaught TypeError: Cannot read property 'length' of undefined

This addresses the issue by checking for a decimal before attempting to format it. The same line from above will now return '-40'

@@ -658,7 +661,7 @@

w = d.split('.')[0];

if (d.split('.')[1].length) {
if (d.split('.').length > 1 && d.split('.')[1].length) {

Choose a reason for hiding this comment

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

mm in here you are doing the split like 4 times .. maybe its better to save the result of the split and then use it

Choose a reason for hiding this comment

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

sounds like a good idea 😄

don't error when an integer is formatted as a decimal with a wildcard.

ex:
`numbro(-40).format('#.*');` will now return `'-40'`

fixes BenjaminVanRyseghem#199, see for more context
@msaglietto
Copy link

THanks @mguida22 I think it looks ok now .. what do you think @BenjaminVanRyseghem could we merge this .. I could use it =P ...

@BenjaminVanRyseghem
Copy link
Owner

thanks 👍

@BenjaminVanRyseghem BenjaminVanRyseghem merged commit 5fa21b0 into BenjaminVanRyseghem:develop Nov 14, 2016
@mguida22
Copy link
Contributor Author

Thanks for the feedback on this!

@BenjaminVanRyseghem
Copy link
Owner

in numbro 1.10.0

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.

3 participants