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

Number formatting #215

Open
andrejhronco opened this issue Oct 5, 2021 · 1 comment
Open

Number formatting #215

andrejhronco opened this issue Oct 5, 2021 · 1 comment

Comments

@andrejhronco
Copy link

andrejhronco commented Oct 5, 2021

Hi,
Thank you for your work on this great package.

I'm displaying floats in the Number element and I would like 1 to display as 1.00.
Since the value is a string, that formatting shouldn't be an issue in JS.

is there a formatting function that I could pass in?
format={(value) => value.toFixed(2)}

also would be useful for displaying units
format={(value) => `${value}ms`}

Appreciate any advice.

@mscottnelson
Copy link
Collaborator

Hello @andrejhronco . There isn't a format function, and there isn't a configuration value. There is, however, already a value present on the object for controlling this, and you can modify it after the object is created (and before the value is set). See below:

let number = new Nexus.Number('#target',{ 'step': 0 });
number.decimalPlaces = 4;
number.value = 0.13;

I have my suspicions about floating-point and nobody wanting to take the time to take it into account, and that this is the reason that it is not currently a documented configuration value.

If you'd like to make a good-faith effort in making sure it doesn't cause issues elsewhere in the codebase, or perhaps in accepting a configurable formatting function that doesn't touch the underlying value, then I'd be more than happy to merge a PR to make this configurable.

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

No branches or pull requests

2 participants