Skip to content

allow a decimal format for an integer#222

Merged
BenjaminVanRyseghem merged 1 commit into
BenjaminVanRyseghem:developfrom
mguida22:decimal-format
Nov 14, 2016
Merged

allow a decimal format for an integer#222
BenjaminVanRyseghem merged 1 commit into
BenjaminVanRyseghem:developfrom
mguida22:decimal-format

Conversation

@mguida22

Copy link
Copy Markdown
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'

Comment thread numbro.js Outdated
w = d.split('.')[0];

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Owner

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
Copy Markdown

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
Copy Markdown
Owner

thanks 👍

@BenjaminVanRyseghem
BenjaminVanRyseghem merged commit 5fa21b0 into BenjaminVanRyseghem:develop Nov 14, 2016
@mguida22

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback on this!

@BenjaminVanRyseghem

Copy link
Copy Markdown
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