Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#13618 closed bug (no change required)

Haiku lacks support for a locale-sensitive decimal point.

Reported by: owenca Owned by: pulkomandy
Priority: normal Milestone: R1/beta1
Component: Kits/Locale Kit Version: R1/Development
Keywords: BFormattingConventions, BFloatFormat, BGenericNumberFormat::FractionSeparator() Cc: pulkomandy, humdinger
Blocked By: Blocking:
Platform: All

Description

It seems that Haiku does not set the default decimal-point character based on the current locale. For example, if the current locale is English, the decimal point should be set to the dot character '.'; if German, the comma character ','.

One possible reason is that BFormattingConventions::GetNumericFormat(BString& outFormat) is not implemented according to its source code.

Change History (5)

comment:1 by pulkomandy, 7 years ago

Indeed, not much was done in terms of formatting numbers in general.

However, there is some support in BNumberFormat. This is what the Locale preferences uses for formatting number and it seems to work.

I will delete BFloatFormat* as these are not needed. Do you need to do something else than formatting numbers? We can add more features to BNumberFormat as needed, but I need some details on your use cases.

comment:2 by owenca, 7 years ago

I tried

BString str;
BNumberFormat fmt;
fmt.Format(str, 0.9);

but it doesn't format 0.9 as 0,9 when I set Deutsch as the preferred language from the Locale window.

I need to know what Haiku uses as the decimal-point symbol under the current locale set by the user so that I can allow/disallow it in a text control.

comment:3 by pulkomandy, 7 years ago

Resolution: no change required
Status: newclosed

After discussing this on IRC and some research, the decimal point support is working fine, however:

  • you need to select a locale in the "formatting" tab in locale preferences. This is independant from the language so that numbers always use the same format, no matter which language are available in the apps you run. Switching from YY/MM/YYYY to MM/DD/YYYY, or from dot as decimal and thousand separator, could lead to confusion, so a single setting for number format is desirable.
  • strtod and other C functions will ignore the settings unless the LC_* environment variables are set (not the case for GUI apps by default). But, using the Locale Kit (BNumberFormat in this case) will work fine.

comment:4 by korli, 7 years ago

As a side note, an example using POSIX localeconv() (the comment from Adrien regarding LC_* variables apply). Weirdly, this works on Haiku, but not on Ubuntu for de_DE and it_IT.

#include <locale.h>
#include <stdio.h>

int main ()
{
   struct lconv * lc;

   setlocale(LC_ALL, "de_DE.UTF-8");
   lc = localeconv();
   printf("Local Currency Symbol: %s\n",lc->currency_symbol);
   printf("International Currency Symbol: %s\n",lc->int_curr_symbol);
   printf("Decimal Point = %s\n", lc->decimal_point);

	setlocale(LC_ALL, "it_IT.UTF-8");
   lc = localeconv();
   printf("Local Currency Symbol: %s\n",lc->currency_symbol);
   printf("International Currency Symbol: %s\n",lc->int_curr_symbol);
   printf("Decimal Point = %s\n", lc->decimal_point);


   setlocale(LC_ALL, "fr_FR.UTF-8");
   lc = localeconv();
   printf("Local Currency Symbol: %s\n",lc->currency_symbol);
   printf("International Currency Symbol: %s\n",lc->int_curr_symbol);
   printf("Decimal Point = %s\n", lc->decimal_point);

   setlocale(LC_ALL, "en_US.UTF-8");
   lc = localeconv();
   printf("Local Currency Symbol: %s\n",lc->currency_symbol);
   printf("International Currency Symbol: %s\n",lc->int_curr_symbol);
   printf("Decimal Point = %s\n", lc->decimal_point);

   setlocale(LC_ALL, "en_GB.UTF-8");
   lc = localeconv();
   printf ("Local Currency Symbol: %s\n",lc->currency_symbol);
   printf ("International Currency Symbol: %s\n",lc->int_curr_symbol);

   printf("Decimal Point = %s\n", lc->decimal_point);
   
   return 0;
}

comment:5 by owenca, 7 years ago

Thanks, pulkomandy and korli!

Note: See TracTickets for help on using tickets.