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

Does not follow user profile configured "Number Format" #1010

Open
howi42 opened this issue Sep 26, 2023 · 23 comments
Open

Does not follow user profile configured "Number Format" #1010

howi42 opened this issue Sep 26, 2023 · 23 comments
Labels
bug Something isn't working enhancement Something that can be improved

Comments

@howi42
Copy link

howi42 commented Sep 26, 2023

the number format, as defined in the profile settings, is not honored.

@ildar170975
Copy link
Collaborator

Same as closed #774

@ildar170975 ildar170975 changed the title number format Does not follow profile configured "Number Format" Sep 29, 2023
@ildar170975 ildar170975 added bug Something isn't working enhancement Something that can be improved and removed bug Something isn't working labels Sep 29, 2023
@ildar170975 ildar170975 changed the title Does not follow profile configured "Number Format" Does not follow user profile configured "Number Format" Sep 29, 2023
@howi42
Copy link
Author

howi42 commented Nov 3, 2023

Regardless the state of this issue, the user interface does not look good with this.
And , I have not found any settings combination ( language, number format, data format ), which at the end use the same style for numbers.

@cataseven
Copy link

Up up up

@Lavve
Copy link

Lavve commented Nov 15, 2023

Would be really nice to get this fixed, it looks a bit strange with different number formats on the dash.

@CMDR-Sloma
Copy link

This should be treated as a bug, not an enhancement.

@cataseven
Copy link

Up

@ildar170975
Copy link
Collaborator

ildar170975 commented Feb 10, 2024

No need to "up" here. It only makes sense to prevent "stale".
Using "upping" to force someone to implement the feature is inappropriate.

@cataseven
Copy link

cataseven commented Feb 10, 2024

Can you please label this as "bug"? This is not an enhc.

@CMDR-Sloma
Copy link

I also agree this is not an enhancement but a bug.

@ildar170975
Copy link
Collaborator

ildar170975 commented Feb 10, 2024

I can set here "bug", but it may not "speed up" implementation...
So, 2 labels - enhancement & bug - everyone is happy))))

@ildar170975 ildar170975 added the bug Something isn't working label Feb 10, 2024
@cataseven
Copy link

cataseven commented Feb 10, 2024

I found my solution. For those want to use "." as thousand seperator and "," for decimals. I am not a developer so I couldnt do it more generic way but It works anyway

  • VSCode and copy the entire js code: "/config/www/community/mini-graph-card/mini-graph-card-bundle.js"

  • https://beautifier.io/ and beuatify the code. Copy it and paste back into the file "/config/www/community/mini-graph-card/mini-graph-card-bundle.js"
    image

  • delete the ".gz" file: /config/www/community/mini-graph-card/mini-graph-card-bundle.js.gz

  • edit dashboard -> manage resources: delete all lines related with "graph" and relink one of them as "local/community/mini-graph-card/mini-graph-card-bundle.js"
    image

  • go VScode and find the line

numberFormat(a, b, c) {
  return !O(+a) && Intl ? new Intl.NumberFormat(b, {
    minimumFractionDigits: c
  }).format(+a) : a.toString()
}

change it with the code below. I prefered Turkish. So now my numbers are now formatted like 1.233.444,89 and I am still using HA in English.

numberFormat(a, b, c) {
  if (!isNaN(+a)) {
    const formattedNumber = (+a).toLocaleString('tr-TR', {
      minimumFractionDigits: c
    });
    return formattedNumber;
  } else {
    return a.toString();
  }
}
  • Restart HA. Clear browser and mobile app cache. Reload page and restart mobile app
    Cheers

@cataseven
Copy link

I can set here "bug", but it may not "speed up" implementation... So, 2 labels - enhancement & bug - everyone is happy))))

Maybe My last suggestion speed it up ;)

@aigarius
Copy link

Not really, cat. The addon should be following the Home Assistant defined settings on the Number Format specifically and not just use the default number format of the language chosen for the HA UI. And also not one random language format. For example, I have HA UI language set to "English", but the Number format to "None" because I can not stand having extra thousand separator symbols. It works (almost) everywhere in HA, but this addon just ignores the very explicit Number format setting and instead tries to guess the number format from the UI language, which is a bug.

@cataseven
Copy link

Not really, cat. The addon should be following the Home Assistant defined settings on the Number Format specifically and not just use the default number format of the language chosen for the HA UI. And also not one random language format. For example, I have HA UI language set to "English", but the Number format to "None" because I can not stand having extra thousand separator symbols. It works (almost) everywhere in HA, but this addon just ignores the very explicit Number format setting and instead tries to guess the number format from the UI language, which is a bug.

Sure, but I at least some of us get what they need. Agree for the rest

@aigarius
Copy link

I wonder if home-assistant/frontend#17249 can be used to get HA to format the values correctly.

@ildar170975
Copy link
Collaborator

May be I am missing something, see no need to connect “number format” and “language”, imho these are independent settings.

@aigarius
Copy link

Yes, they are. Currently the code in mini-graph-card just uses "language" setting and then asks an external library to format numbers (and dates) in accordance to the rules of that language. And completely ignores the HA settings for number format and date format.

@ildar170975
Copy link
Collaborator

And in HA itself there are some “connections” between a language and a number format - which makes a code more complex and buggy.

@aigarius
Copy link

There are indeed, like if I click on a value I get this wonderful screen:
Screenshot from 2024-02-20 15-00-46

That screen has both correct number formatting preference (None) in the number display location (top right, "1078 ppm"), but at the same time chooses to use the language numbering preference for the Y axis ("2,000")

The second is a bug.

@ildar170975
Copy link
Collaborator

What happens if you start playing with a language, will it affect mini-graph?

@aigarius
Copy link

Yes, switching from "English" to German, for example, would change the decimal separator from "." to "," and the thousand separator from "," to ".". And switching language to Esperanto would change the thousand separator to " " and decimal separator to ",".

The code in https://github.com/kalkih/mini-graph-card/blob/master/src/main.js#L720 literally just gives the value to the browser function Intl.NumberFormat along with the currently configured system language.

@aigarius
Copy link

https://developers.home-assistant.io/docs/frontend/data/#hassformatentityattributevaluestateobj-attribute-value describes the function that is there to format the value correctly, according to settings of both HA and of the entity itself (like you can set precision on the entity). It is available to mini-graph-card.

@dr3amr
Copy link

dr3amr commented May 13, 2024

@ildar170975 @kalkih Any development to current issue ? No updates from Feb 20, is this still considered for implementation ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement Something that can be improved
Projects
None yet
Development

No branches or pull requests

7 participants