globalizejs / globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
https://globalizejs.com
MIT License
4.8k stars 605 forks source link

Percent format and parsing #940

Closed alc86 closed 8 months ago

alc86 commented 1 year ago

Hi,

I have recognised that the formatting and parsing currently work with factor 100. So this means value 1 is formatted to 100% and 100% is parsed to 1. Is there a possibilty to change the factor because we would like to have value 1 as 1% and 1% should be parsed to value 1.

pau1tuck commented 8 months ago

@alc86, could you elaborate on "currently work with factor 100" please? Do you mean that the numberFormatter and numberParser are returning incorrect values specifically for 1 and 100%?.numberFormatter({ style: "percent" })( 0.5 ) // > "50%" .numberParser({ style: "percent" })( "50%" ) // > 0.5

rxaviers commented 8 months ago

Thank you @pau1tuck for asking for clarification. I think @alc86 wants to be able to pass 1 and get "1%" as output.

@alc86 that can be accomplished by dividing the input before passing it to globalize, like x/100. That said, I don't foresee a need for globalize API to change. Let me know if you need something else or if this blocks any use case I couldn't anticipate here. Thanks