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

[Issue]: How to format number in NumberInput #922

Open
alamenai opened this issue Jan 22, 2024 · 2 comments
Open

[Issue]: How to format number in NumberInput #922

alamenai opened this issue Jan 22, 2024 · 2 comments
Labels
Type: Enhancement Small enhancement to existing component or feature

Comments

@alamenai
Copy link

Tremor Version

latest

Link to minimal reproduction

.

Steps to reproduce

I have a NumberInput and I want the German number format. In German, they use comma , instead of . fr their float numbers.

Code

 const handleNumberInputChange = (property: string, value: number) => {

   // Currently, the user enters numbers in this format 1.1 | 2.2
  // However, I want him that format 1,1 | 2,2
    dispatch(updatePanelMeasures({ ...measures, [property]: value }))
  }

 <NumberInput
          icon={TextQuote}
          placeholder='1.1'
          max={1}
          min={0.1}
          step={0.1}
          className='mt-2 min-h-11'
          value={measures.border}
          onValueChange={(border) => handleNumberInputChange("border", border)}
        />

What is expected?

.

What is actually happening?

.

What browsers are you seeing the problem on?

No response

Any additional comments?

No response

@christopherkindl christopherkindl added the Type: Enhancement Small enhancement to existing component or feature label Jan 23, 2024
@CoHarsh
Copy link

CoHarsh commented Feb 18, 2024

This looks interesting.
I am wondering whether to extend this to German number format or make this general. @christopherkindl

@hikinine
Copy link

Would be awesome if we receive as optional props an "formatter" which represents Intl.NumberFormat constructor
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat

So we separate the render value from the reference value

return (
   <NumberInput  
        defaultValue={123456.79}
        formatter={ new Intl.NumberFormat('en-US', { style: 'currency', currency: "USD" }) } 
    />
)

  DISPLAY VALUE:  '$123,456.79'
  REF VALUE:   123456.79

I am available to work on this if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Small enhancement to existing component or feature
Projects
None yet
Development

No branches or pull requests

4 participants