Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hi there,
We're making extensive use of formatjs for i18n, so first up – thanks for the hard work!

Next, we're working with forms where the inputs will be undertaken in a localised format. The numbers going in are great – number skeletons make use of scale allowing us to transform from our internal number system to the partner's desired format. The problem is, when the user enters a value, we need to reverse transform the value based on the number skeleton.

That is:

  • supported: number -> presented value
  • needed: presented number -> number

Any thoughts on best strategy to adopt to enable this?

You must be logged in to vote

Replies: 1 comment · 4 replies

Comment options

That's inherently a fairly tricky problem. Solutions I've seen are mostly around supporting only decimal separator which narrows down to either . or , then parse number from there.
It's impossible to parse a formatted number without knowing the options it was formatted with.

You must be logged in to vote
4 replies
@jufemaiz
Comment options

Fair. But we know this via the same inputs that are used to render it. They are required, otherwise we cannot present.

Three things needed are:

  1. Value
  2. Format
  3. Locale

Nothing else right?

@longlho
Comment options

With input you also need to ability to accept partial number/result, e.g 100. and with the combination of options it's still fairly hard. TBH I don't know of anything off the shell to parse a string even given a format. It's not a 1-1 mapping, as in 1 output can come from many numbers + formats.

@jufemaiz
Comment options

Sure, but let's say we know the format.

Use case:

  • data is stored in format A.
  • data is presented in a localised format, set by an i18n file, supporting the locale of choice.
  • the locally presented data is in a form input
  • the input data can be modified by a user
  • onChange/onUpdate/onSubmit that needs to be converted back (we do know the locale + format used, and we do know the new value)

So while what you say is absolutely true, we're not attempting to divine the format. Looking for a confirmation of the above three things given the example provided.

@longlho
Comment options

yeah sorry I'm not aware of any out-of-the-box solution for that :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
💡
Ideas
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.