Skip to content

new NumberRenderer<>(provider, locale) does not format numbers according to locale #8970

Closed

Description

@Legioth

The NumberRenderer(ValueProvider, Locale) constructor ends up using String.format(locale, "%s", value) where %s in the format string is defined to use the value as a Formattable if it implements that interface and otherwise uses toString() on the value. Since e.g. Double or Integer doesn't implement Formattable, the end result is that numbers are formatted using toString() which uses the JVM default locale without taking the provided locale into account. The end result is thus that numbers are not formatted according to the provided locale.

Using the NumberRenderer(ValueProvider, NumberFormat) constructor instead (using e.g.NumberFormat.getInstance(locale) to get a NumberFormat instance) works as exected.

Activity

  1. changed the title [-]new NumberFormatter<>(provider, locale) does not format numbers according to locale[/-] [+]new NumberRenderer<>(provider, locale) does not format numbers according to locale[/+] on Sep 2, 2020
  2. pleku commented on Nov 24, 2020

    @pleku

    This has been working like this since 1.0 with the javadocs of

         * The renderer is configured to render with the number's natural string
         * representation in the given locale.

    so it is on the borderline as "the numbers natural string representation in the given locale" is not entirely obvious, but probably one could expect it to try to behave the same as when creating the NumberFormat out of the locale. The javadocs could be clarified then too. But I'll mark this as a bug.

  3. Legioth commented on Nov 24, 2020

    @Legioth
    MemberAuthor

    What is the purpose of a NumberRenderer(ValueProvider, Locale) constructor other than to format numbers based on the provided locale?

    As it's currently implemented, the locale parameter seems to not have any practical impact at all except in the special case with a value provider that returns a custom Number subtype that also implements Formattable (none of the bulit-in ones do).

    I expect that new NumberRenderer<Object>(ignore -> Double.valueOf(1.2), new Locale("fi")) would render values as 1,2 whereas the same with Locale.ENGLISH would render values as 1.2. With the current implementation, both variants format the number according to the JVM's default locale.

  4. added a commit that references this issue on Jul 2, 2021
    acd7142
  5. added a commit that references this issue on Jul 6, 2021
    813dd86
  6. added 6 commits that reference this issue on Jul 6, 2021
    82d32b2
    2d54084
    8baa073
    250c31d
    5f2a45d
    88b1016
  7. vaadin-bot commented on Jul 15, 2021

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with platform 14.6.6. For prerelease versions, it will be included in its final version.

  8. vaadin-bot commented on Jul 26, 2021

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with platform 20.0.5. For prerelease versions, it will be included in its final version.

  9. vaadin-bot commented on Aug 6, 2021

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with platform 21.0.0.beta1 and is also targeting the upcoming stable 21.0.0 version.

  10. vaadin-bot commented on Aug 9, 2021

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with platform 14.7.0.alpha3 and is also targeting the upcoming stable 14.7.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata