Recent

Author Topic: Broken char through Format() with ThousandSeparator = NBSP  (Read 798 times)

anse

  • New Member
  • *
  • Posts: 23
  • Bugmonkey
    • HeidiSQL
Broken char through Format() with ThousandSeparator = NBSP
« on: June 11, 2025, 11:25:02 am »
I have some users with ru-RU locale, which has ThousandSeparator = #160 (no-break-space, looks like a space but allows no line break).
Formatting numbers in their locale shows a broken ThousandSeparator, see attached images.
First one is done on a ru-RU Linux system, second one on my own de-DE Windows where I testwise set that nbsp char:
Code: Pascal  [Select][+][-]
  1. DefaultFormatSettings.ThousandSeparator:= chr(160);
Both are generated through:
Code: Pascal  [Select][+][-]
  1. Format('%.0n', [aValue + 0.0])


Confusing to me is that nbsp is even in the ASCII and LATIN1 charset.

Is it known that Format cannot handle certain diacritical characters?

There's a 9 year old post saying this is not supported by FPC: https://forum.lazarus.freepascal.org/index.php/topic,32159.msg207284.html#msg207284

paweld

  • Hero Member
  • *****
  • Posts: 1435
Re: Broken char through Format() with ThousandSeparator = NBSP
« Reply #1 on: June 11, 2025, 11:47:15 am »
Lazarus treats strings as UTF-8 so you need to convert formatted value to UTF8:
Code: Pascal  [Select][+][-]
  1. uses
  2.   LazUTF8;
  3.  
  4. var
  5.   fs: TFormatSettings;
  6. begin
  7.   fs.ThousandSeparator := #160;
  8.   Caption := WinCPToUTF8(Format('%.0n', [123456.0], fs)); //or CP1251ToUTF8 from LConvEncoding unit
  9. end;
« Last Edit: June 11, 2025, 11:49:28 am by paweld »
Best regards / Pozdrawiam
paweld

anse

  • New Member
  • *
  • Posts: 23
  • Bugmonkey
    • HeidiSQL
Re: Broken char through Format() with ThousandSeparator = NBSP
« Reply #2 on: June 11, 2025, 01:52:24 pm »
Thanks a lot @paweld. LazUTF8.WinCPToUTF8 showed up another (broken) character instead of the question mark. But it looks like LConvEncoding.CP1251ToUTF8 is doing the right thing - at least on Windows, but I guess the Linux version does the same.

paweld

  • Hero Member
  • *****
  • Posts: 1435
Re: Broken char through Format() with ThousandSeparator = NBSP
« Reply #3 on: June 11, 2025, 03:30:44 pm »
LazUTF8.WinCPToUTF8 showed up another (broken) character instead of the question mark.
probably because the Windows code page is not Latin1
Best regards / Pozdrawiam
paweld

 

TinyPortal © 2005-2018