Recent

Author Topic: Format with thousands separator  (Read 15693 times)

bmy92

  • New Member
  • *
  • Posts: 11
Format with thousands separator
« on: March 07, 2013, 10:48:25 am »
Hi all,

I am a new user of Lazarus 1.06 (FPC 2.6.0), coming from Delphi.
My OS : Windows XP, french.

This instruction :
Code: [Select]
ShowMessage( Format('%10.0n', [1234567.0]) )displays: 1?234?567
Apparently, FPC produces an incorrect thousands separator (a space in my french locale)
Delphi 7 on the same computer correctly gives :  1 234 567

Did I forget something ?

bigeno

  • Sr. Member
  • ****
  • Posts: 266
Re: Format with thousands separator
« Reply #1 on: March 07, 2013, 11:03:22 am »
You should set default.
DefaultFormatSettings.ThousandSeparator:=' ';

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Format with thousands separator
« Reply #2 on: March 07, 2013, 11:19:50 am »
Strange.

Your sample code worked for me (it gave me a period which is correct for my locale) with laz 1.0.6+FPC 2.6.0 as well as Laz trunk +FPC trunk on Vista x64.

Perhaps it's a bug with xp + FPC!?
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

bmy92

  • New Member
  • *
  • Posts: 11
Re: Format with thousands separator
« Reply #3 on: March 07, 2013, 12:15:36 pm »
I see the same error with my new laptop with Windows 8, french.

Format does take into account the locale for the decimal separator (comma for France), but seems to bug with the thousands separator.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Format with thousands separator
« Reply #4 on: March 07, 2013, 01:43:19 pm »
I add unit "clocale" to uses section of *.lpr file and I can reproduce on Linux. This should be reported.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

bmy92

  • New Member
  • *
  • Posts: 11
Re: Format with thousands separator
« Reply #5 on: March 07, 2013, 03:13:14 pm »
The variable ThousandSeparator of sysutils is also incorrectly initialized.

I have created bug report 0024011 http://bugs.freepascal.org/view.php?id=24011

bmy92

  • New Member
  • *
  • Posts: 11
Re: Format with thousands separator
« Reply #6 on: March 14, 2013, 02:43:26 pm »
The bug report 0024011 was finally resolved as "No change required".
This is what I have understood (after hard thinking and many tests).

The non-breaking space provided with the Format function is a character of ordinal value 160 (hexadecimal A0).
This is non-breaking space in Ansi, but we need it in UTF8 encoding, that is hexadecimal C0 A0, or decimal: 192 160

The original problem seems solved with
Code: [Select]
ShowMessage(AnsiToUTF8(Format('%10.0n', [1234567.0])));
But the solution does not work if you have national characters and non-breaking spaces. This will display badly:
Code: [Select]
showMessage(AnsiToUTF8(Format('%10.0n mètres', [1234567.0])));A correct solution is to only convert the Ansi non-breaking space
Code: [Select]
showMessage(AnsiReplaceStr(Format('%10.0n mètres', [1234567.0]), #160, #192#160));


Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Format with thousands separator
« Reply #7 on: March 14, 2013, 04:20:01 pm »
It does not work for me in console too. When I try simple program:
Code: [Select]
uses clocale, sysutils;

begin
  writeln(FormatSettings.ThousandSeparator);
  writeln(Format('%10.3n', [1234567.0]));
end.
and in console:
Code: [Select]
fpc format.pas
./format

1�234�567,000
Note that I have set no group separator for numbers and '.' for money in KDE4.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

tintinux

  • Sr. Member
  • ****
  • Posts: 325
    • Gestinux
Re: Format with thousands separator
« Reply #8 on: September 14, 2015, 01:48:09 pm »
Hi,

But don't you think that the best and most natural solution is :

  • the separator is converted during initialization to UTF8 or other charset if requested by the application
  • the Format functions accept a multi-byte char as Thousand separator.

I think that other solutions have side effects and may lead to issues in some specific cases and environments.

And this way LazReport and other libraries will work with this separator and without any change.

Regards
« Last Edit: September 14, 2015, 01:52:18 pm by tintinux »
Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Format with thousands separator
« Reply #9 on: September 14, 2015, 01:50:23 pm »
(afaik this is already fixed in newer releases)

tintinux

  • Sr. Member
  • ****
  • Posts: 325
    • Gestinux
Re: Format with thousands separator
« Reply #10 on: September 14, 2015, 01:56:05 pm »
Good new, thanks !

However it is not fixed in 1.4.2
 
If someone knows in which version, I'm interested. Is it in FPC or Lazarus ?
Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Format with thousands separator
« Reply #11 on: September 14, 2015, 02:26:38 pm »
It is not resolved it seems.  FPC is in ansi, LCL requires utf8, and that bites.

Post http://forum.lazarus.freepascal.org/index.php/topic,20163.msg116623.html#msg116623 says it all.

I remember there being a bugreport but erroneously assumed it was fixed. It wasn't it was not fixable.

otoien

  • Jr. Member
  • **
  • Posts: 89
Re: Format with thousands separator
« Reply #12 on: September 15, 2015, 05:08:57 am »
BTW, I have never got the console output to work with UTF-8 (opposed to the same write command to a text file). This applies even when using the fixes branch with fpc 3.01 and UTF-8 active in RTL (no FPC-LCL inconsistency), so it seems that console output is not a good test case?
« Last Edit: September 15, 2015, 05:18:57 am by otoien »
Unless otherwise noted I always use the latest stable version of Lasarus/FPC x86_64-win64-win32/win64

tintinux

  • Sr. Member
  • ****
  • Posts: 325
    • Gestinux
Re: Format with thousands separator
« Reply #13 on: September 16, 2015, 01:26:51 pm »
Hi

I have created a bug in FPC, to make possible to assign a multibyte character to separators.

Regards
Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

otoien

  • Jr. Member
  • **
  • Posts: 89
Re: Format with thousands separator
« Reply #14 on: September 17, 2015, 02:29:38 am »
It is not resolved it seems.  FPC is in ansi, LCL requires utf8, and that bites.

Post http://forum.lazarus.freepascal.org/index.php/topic,20163.msg116623.html#msg116623 says it all.

I remember there being a bugreport but erroneously assumed it was fixed. It wasn't it was not fixable.

Even with both FPC and LCL set to UTF-8 with FPC 3.01 this is not solved according to my testing.

It could be solved by redefining the FormatSettings.ThousandSeparator to a string type. Then it could be assigned the proper UTF-8 code for Thin Space (U+2009) when needed. I do not know how much code would break because of this though.

The operative system's settings must also be able to deal with this - I wonder how it is defined there.

It seems that thin space as a grouping separator is gaining international support,
from  https://en.wikipedia.org/wiki/Decimal_mark :
" ...the International Bureau of Weights and Measures and International Union of Pure and Applied Chemistry advocate the use of a "thin space" in "groups of three".[15][16] Within the United States, the American Medical Association's widely followed AMA Manual of Style also calls for a thin space.[13]"
« Last Edit: September 17, 2015, 02:45:36 am by otoien »
Unless otherwise noted I always use the latest stable version of Lasarus/FPC x86_64-win64-win32/win64

 

TinyPortal © 2005-2018