Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Issue with negative decimal number without integer part #11

Closed
outaTiME opened this issue Apr 20, 2021 · 6 comments
Closed

Issue with negative decimal number without integer part #11

outaTiME opened this issue Apr 20, 2021 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@outaTiME
Copy link

outaTiME commented Apr 20, 2021

I am using the following code and it removes the integer part, the output should be -0,5 but it is -,5, is this correct? or could it be solved?

prettyMoney(
  {
    decimalDelimiter: ',',
    thousandsDelimiter: '.',
    minDecimal: 0,
    maxDecimal: 2,
  },
  -0.5
) // outputs: '-,50'

If you try it on your example page with the default configuration, the same thing happens 😢

@outaTiME
Copy link
Author

outaTiME commented Apr 20, 2021

BTW, as you see minDecimal setting is ignored too 😭

@kytta kytta added the bug Something isn't working label Apr 20, 2021
@kytta kytta self-assigned this Apr 20, 2021
@kytta
Copy link
Owner

kytta commented Apr 20, 2021

Yup, can see the issue. I'll try to look into it this week and fix it.

BTW, as you see minDecimal setting is ignored too 😭

Hmm, this one I actually can't confirm on the website 🤔

image

But since I'm changing the algorithm completely it should also be fixed

@outaTiME
Copy link
Author

outaTiME commented Apr 20, 2021

Hi @NickKaramoff,
with respect to minDecimal, as can be seen in my example I use minDecimal: 0 and maxDecimal: 2, therefore the number should be displayed formatted with the number of decimal places entered (because it is in range) if min and max were 2 (as seen in your picture) it's okay to show two decimal places.

Notice that it has the same formatting effect putting 0, 2 as 2, 2:

image

@kytta
Copy link
Owner

kytta commented Apr 20, 2021

Ah, I see. For this effect you need to use the fluid mode.

In the minmax mode the amount of decimal places is minDecimal, if possible, and maxDecimal otherwise. In the fluid mode the amount of decimal places is the one closest to the input number and clamped between minDecimal and maxDecimal

@outaTiME
Copy link
Author

outaTiME commented Apr 20, 2021

Understood, thanks for the clarification 🙌

The setting name minmax means that both values are used as if they were Intl.NumberFormat.

Wouldn't it be better for the default to be fluid to avoid misinterpretations?

In some cases using this new setting generates problems with number rounding, here is the capture:

image

@kytta
Copy link
Owner

kytta commented Feb 17, 2022

I'm sorry, Ariel, but this project is now archived; I will not maintain it any further. Use Number.prototype.toLocaleString(); it works correctly starting with Node 14, is built-in, and has no bugs.

@kytta kytta closed this as completed Feb 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants