Lazarus

Programming => General => Topic started by: Milsa on August 01, 2020, 04:49:29 pm

Title: IntToStr with national convention?
Post by: Milsa on August 01, 2020, 04:49:29 pm
I want convert number to  eye like format with national convenstions:

123456789 => '123 456 789' for SK language setting
123456789 => '123,456,789' for EN language setting

etc.

Conversion must be automatic by language selection. What command should I use?
Title: Re: IntToStr with national convention?
Post by: process_1 on August 01, 2020, 05:26:59 pm
The easiest way is with format():

https://www.freepascal.org/docs-html/rtl/sysutils/format.html
Title: Re: IntToStr with national convention?
Post by: PascalDragon on August 01, 2020, 05:32:34 pm
Format as suggested by process_1 supports the thousand separator only for floating point numbers which might result in a precision loss.

Alternatively you can use the FmtBCD unit where you first convert your integer number to a tBCD (best by using the operator overloads) and then to a string by using BCDToStr with the FormatSettings overload. Correction. That does not work...  %)
Title: Re: IntToStr with national convention?
Post by: dsiders on August 01, 2020, 06:03:15 pm
I want convert number to  eye like format with national convenstions:

123456789 => '123 456 789' for SK language setting
123456789 => '123,456,789' for EN language setting

etc.

Conversion must be automatic by language selection. What command should I use?

I use the following technique:

Code: Pascal  [Select][+][-]
  1.   {
  2.     var
  3.        i: Integer;
  4.        s: String;
  5.   }
  6.  
  7.   { just to prove use of current locale settings }
  8.   DefaultFormatSettings.ThousandSeparator := '~';
  9.  
  10.   i := 123456789;
  11.   s := FormatFloat('#,##0', i.ToDouble, DefaultFormatSettings);
  12.   // s := FormatFloat('#,##0', i.ToExtended, DefaultFormatSettings);
  13.   ShowMessage(s);
  14.  
Title: Re: IntToStr with national convention?
Post by: wp on August 01, 2020, 06:08:38 pm
I want convert number to  eye like format with national convenstions:

123456789 => '123 456 789' for SK language setting
123456789 => '123,456,789' for EN language setting

etc.

Conversion must be automatic by language selection. What command should I use?
If you mean that the decimal/thousand separators must be selected automatic according to your language there is nothing to be done. All the string conversion functions use the correct separators according to your FormatSettings. (Note that you must add unit CLocale to uses on *nix).

If you mean that you have a multi-language program and you want to make the program use the separators according to the language selection of the user then you have a difficult task. A good solution exists only for Windows based on the LCID values. Have a look at the demo in the folder examples/translation of your Lazarus installation; unit "LocalizedForms" contains LCID related code. On other operating systems, however, you are out of luck (to my knowledge, which may be wrong), and you have to provide all the related tables yourself. In any case the FormatSettings with the appropriate separators must be added to the conversion routines as last parameter.

PascalDragon, wouldn't a locale-dependent table of the most important FormatSettings be a useful extension to SysUtils?
Title: Re: IntToStr with national convention?
Post by: PascalDragon on August 01, 2020, 06:58:36 pm
PascalDragon, wouldn't a locale-dependent table of the most important FormatSettings be a useful extension to SysUtils?

What is not important for one user might be important for the other. So that's not a good idea, not to mention that it shouldn't be our task to maintain these tables.

Instead one might extend the clocale unit with a similar function as the Windows' SysUtils.GetLocaleFormatSettings function if the OS supports it (the Android variant of clocale has GetAndroidFormatSettings for example).
Title: Re: IntToStr with national convention?
Post by: process_1 on August 01, 2020, 07:00:39 pm
If your integer number have up to, including 15 digits, you are safe from any rounding error.

Here is an example with format, even FormatFloat mentionied in some previous post  sometimes much more usefull:

Code: Pascal  [Select][+][-]
  1.  
  2. program Test;
  3. var
  4.   ts: char;
  5. begin
  6.      
  7.   ts := ThousandSeparator;
  8.    
  9.   ThousandSeparator := ',';
  10.   writeln(format('%0.n',[0.0]));
  11.   writeln(format('%0.n',[-123456789*1.0]));
  12.   writeln(format('%0.n',[123456789*1.0]));
  13.  
  14.   ThousandSeparator := ' ';
  15.   writeln(format('%0.n',[0.0]));
  16.   writeln(format('%0.n',[-123456789*1.0]));
  17.   writeln(format('%0.n',[123456789*1.0]));
  18.  
  19.   ThousandSeparator := ts;
  20.    
  21. end.
  22.  
  23.  

If you want full integer or int64 range to be supported, there is nothing you can do than make your own function have inttostr(), or int64tostr() and then manually insert separator on each third place inside string result.
Title: Re: IntToStr with national convention?
Post by: Milsa on August 01, 2020, 07:09:15 pm
If you mean that you have a multi-language program and you want to make the program use the separators according to the language selection of the user then you have a difficult task. A good solution exists only for Windows based on the LCID values. Have a look at the demo in the folder examples/translation of your Lazarus installation; unit "LocalizedForms" contains LCID related code. On other operating systems, however, you are out of luck (to my knowledge, which may be wrong), and you have to provide all the related tables yourself. In any case the FormatSettings with the appropriate separators must be added to the conversion routines as last parameter.

PascalDragon, wouldn't a locale-dependent table of the most important FormatSettings be a useful extension to SysUtils?
Multi-language application with FormatSettings texts in PO file is solution too. Or?
Title: Re: IntToStr with national convention?
Post by: wp on August 01, 2020, 07:33:27 pm
Good idea. You must declare resource string for all the strings used by the FormatSettings, and you must provide a routine which copies these translated strings to the currently used FormatSettings record.

On the other hand, it is an unnecessary burden for translators because all this information is available inside Windows and, as PascalDragon wrote, Android. I cannot imagine that locale information cannot be pulled out of Linux/Unix/macOS.
Title: Re: IntToStr with national convention?
Post by: Bart on August 01, 2020, 11:06:23 pm
Can't you just insert the DefaultFormatSettings.ThousandSeparator manually?
Rather crude (and slow, so plenty room for optimization):

Code: Pascal  [Select][+][-]
  1. function IntToStr(Value: UInt64; const TS: String): String; overload;
  2. begin
  3.   Str(Value, Result);
  4.   if (TS = '') then
  5.     Exit;
  6.   if (Value > 999) then
  7.     Insert(TS, Result, Length(Result)-2);
  8.   if (Value > 999999) then
  9.     Insert(TS, Result, Length(Result)-6);
  10.   if (Value > 999999999) then
  11.     Insert(TS, Result, Length(Result)-10);
  12.   if (Value > 999999999999) then
  13.     Insert(TS, Result, Length(Result)-14);
  14.   if (Value > 999999999999999) then
  15.     Insert(TS, Result, Length(Result)-18);
  16.   if (Value > 999999999999999999) then
  17.     Insert(TS, Result, Length(Result)-22);
  18. end;
  19.  
  20. function IntToStr(Value: Int64; const TS: String): String; overload;
  21. begin
  22.   Str(Value, Result);
  23.   if (TS = '') then
  24.     Exit;
  25.   if (Value > 999) or (Value < -999) then
  26.     Insert(TS, Result, Length(Result)-2);
  27.   if (Value > 999999) or (Value < -999999)then
  28.     Insert(TS, Result, Length(Result)-6);
  29.   if (Value > 999999999) or (Value < -999999999) then
  30.     Insert(TS, Result, Length(Result)-10);
  31.   if (Value > 999999999999) or (Value < -999999999999) then
  32.     Insert(TS, Result, Length(Result)-14);
  33.   if (Value > 999999999999999) or (Value < -999999999999999) then
  34.     Insert(TS, Result, Length(Result)-18);
  35.   if (Value > 999999999999999999) or (Value < -999999999999999999) then
  36.     Insert(TS, Result, Length(Result)-22);
  37. end;
  38.  
  39. var
  40.   S, Sep: String;
  41.   U: UInt64;
  42.   I: Int64;
  43. begin
  44.   Sep := DefaultFormatSettings.ThousandSeparator;
  45.   U := High(UInt64);
  46.   S := IntToStr(U,Sep);
  47.   writeln(U,' -> ',S);
  48.   I := High(Int64);
  49.   S := IntToStr(I,Sep);
  50.   writeln(I,' -> ',S);
  51.   I := Low(Int64);
  52.   S := IntToStr(I,Sep);
  53.   writeln(I,' -> ',S);
  54. end.

Outputs (Dutch locale):
Code: [Select]
C:\Users\Bart\LazarusProjecten\ConsoleProjecten>test
18446744073709551615 -> 18.446.744.073.709.551.615
9223372036854775807 -> 9.223.372.036.854.775.807
-9223372036854775808 -> -9.223.372.036.854.775.808

I made TS a string, because it allows to use UTF8 codepoints (hey, I'm on Lazarus).

Bart
Title: Re: IntToStr with national convention?
Post by: Bart on August 02, 2020, 11:01:50 pm
And that contained a bug.
This should work correctly:
Code: Pascal  [Select][+][-]
  1. function IntToStr(Value: UInt64; const TS: String): String; overload;
  2. var
  3.   TSLen: Integer;
  4. begin
  5.   Str(Value, Result);
  6.   if (TS = '') then
  7.     Exit;
  8.   TSLen := Length(TS);
  9.   if (Value > 999) then
  10.     Insert(TS, Result, Length(Result)-2);
  11.   if (Value > 999999) then
  12.     Insert(TS, Result, Length(Result)-5-TSLen);
  13.   if (Value > 999999999) then
  14.     Insert(TS, Result, Length(Result)-8-2*TSLen);
  15.   if (Value > 999999999999) then
  16.     Insert(TS, Result, Length(Result)-11-3*TSLen);
  17.   if (Value > 999999999999999) then
  18.     Insert(TS, Result, Length(Result)-14-4*TSLen);
  19.   if (Value > 999999999999999999) then
  20.     Insert(TS, Result, Length(Result)-17-5*TSLen);
  21. end;
  22.  
  23. function IntToStr(Value: Int64; const TS: String): String; overload;
  24. var
  25.   TSLen: Integer;
  26. begin
  27.   Str(Value, Result);
  28.   if (TS = '') then
  29.     Exit;
  30.   TSLen := Length(TS);
  31.   if (Value > 999) or (Value < -999) then
  32.     Insert(TS, Result, Length(Result)-2);
  33.   if (Value > 999999) or (Value < -999999)then
  34.     Insert(TS, Result, Length(Result)-5-TSLen);
  35.   if (Value > 999999999) or (Value < -999999999) then
  36.     Insert(TS, Result, Length(Result)-8-2*TSLen);
  37.   if (Value > 999999999999) or (Value < -999999999999) then
  38.     Insert(TS, Result, Length(Result)-11-3*TSLen);
  39.   if (Value > 999999999999999) or (Value < -999999999999999) then
  40.     Insert(TS, Result, Length(Result)-14-4*TSLen);
  41.   if (Value > 999999999999999999) or (Value < -999999999999999999) then
  42.     Insert(TS, Result, Length(Result)-17-5*TSLen);
  43. end;

And this is slightly faster:
Code: Pascal  [Select][+][-]
  1. //only works if Length(AThousandSep) <= 4, which should allow for any UTF8 codepoint
  2. function InsertThousandSep(const ValueS, AThousandSep: String): String;
  3. const
  4.   MaxLen = Length('18    446    744    073    709    551    615');   //MaxUInt64
  5. var
  6.   ResPos, SLen, i, j, SpaceCount: Integer;
  7. begin
  8.   Result := StringOfChar(#32,MaxLen);
  9.   SLen := Length(ValueS);
  10.   ResPos := MaxLen;
  11.   for i := Length(ValueS) downto 1 do
  12.   begin
  13.     if ((SLen-i) in [3,6,9,12,15,18]) {and (i <> 1)} then
  14.     begin
  15.       for j := Length(AThousandSep) downto 1 do
  16.       begin
  17.         Result[ResPos] := AThousandSep[j];
  18.         Dec(ResPos);
  19.       end;
  20.     end;
  21.     Result[ResPos] := ValueS[i];
  22.     Dec(ResPos);
  23.   end;
  24.   SpaceCount := 0;
  25.   i := 1;
  26.   while (Result[i] = #32) do
  27.   begin
  28.     Inc(SpaceCount);
  29.     Inc(i);
  30.   end;
  31.   if (SpaceCount > 0) then
  32.     System.Delete(Result, 1, SpaceCount);
  33. end;
  34.  
  35. function IntToStr(Value: UInt64; const TS: String): String; overload;
  36. var
  37.   S: String;
  38. begin
  39.   if (TS = '') then
  40.     Exit(IntToStr(Value));
  41.   Str(Value, S);
  42.   Result := InsertThousandSep(S, TS);
  43. end;
  44.  
  45. function IntToStr(Value: Int64; const TS: String): String; overload;
  46. var
  47.   S: String;
  48. begin
  49.   if (TS = '') then
  50.     Exit(IntToStr(Value));
  51.   Str(Value, S);
  52.   Result := InsertThousandSep(S, TS);
  53. end;

Bart
Title: Re: IntToStr with national convention?
Post by: winni on August 02, 2020, 11:25:35 pm
Hi!

This procedure inserts a blockchar every blocklen counted from the end.
Use a  blocklen of 2 to show hexadecimals and 3 to show decimals.
blockchar should be your national separator


Code: Pascal  [Select][+][-]
  1. function goodLooking (s: string; blocklen: integer; blockchar : char) : string;
  2. var i,k : integer;
  3.      begin
  4.        result := ''; k := 1;
  5.        for i := length(s) downto 1 do
  6.        begin
  7.                 result := s[i]+result;
  8.                 if (k mod Blocklen = 0) and (i>1) then result := blockchar+ result;
  9.                 inc (k);
  10.         end;
  11.      end;
  12.  

Winni
Title: Re: IntToStr with national convention?
Post by: Bart on August 02, 2020, 11:49:49 pm
Appr. 3.8 times slower (and only caters for chars)  O:-)
(I guess repeated insert() kills the speed, tested with High(UInt64) as input, so probably worst case scenario.)

Bart
Title: Re: IntToStr with national convention?
Post by: winni on August 02, 2020, 11:55:18 pm
Hi Bart!

I knew it before that this is to simple for you .....

And it should only be used for digits or hexdigits:
all ASCII.

Or do you print your numbers in UTF8-Cherokee?

Winni

Title: Re: IntToStr with national convention?
Post by: winni on August 03, 2020, 12:13:05 am
Awful slow.

0.000569  Milliseconds. Awful slow.
You really recognize it.

For those who live in a world with seconds:
0.000000569 seconds

Winni


Title: Re: IntToStr with national convention?
Post by: Bart on August 03, 2020, 12:55:34 pm
Or do you print your numbers in UTF8-Cherokee?

Some national thousandseparators are not single byte (at least not when you use Lazarus, where evrything is UTF8).
Hence my use of a string instead of a char.

Bart
Title: Re: IntToStr with national convention?
Post by: Bart on August 03, 2020, 01:04:33 pm
For those who live in a world with seconds:
0.000000569 seconds

Sorry, but I just couldn't resist posting that.

Mind you: I do not really care that much (you might have noticed the emoticon I uses).
There are however plenty of speedfreaks around here.

In the distant past I had a discussion in the bugtracker that my new implementation of some conversion to string was 4 times slower than the original.
The original however gave you the worng results.
My opponent in that discussion found that a wrong result was less of an issue than speed.
Even then you would have to do > 100 thousand conversions to notice the difference, which actually might be a use case, but in such a scenario the input was probably read from a file, which would have been the bottle neck for the entire operation (IO is way slower than conversion code).

You code has the added advantage it can be used for strings of any length (my code could easily be adopted for that if the need arises) and it can do 2 jobs (mine only one).

So, no hard feelings I hope?

Bart
Title: Re: IntToStr with national convention?
Post by: process_1 on August 03, 2020, 02:07:02 pm
Milsa,

Try this. I have made and used something similar when I needed 4 digits separator and full range for int64, it is actually universal. This is just recreated from memory:

Code: Pascal  [Select][+][-]
  1. function IntToStrFormat(Value: int64; ASeparator: char; ALen: integer = 3): string;
  2. var
  3.   i, c: integer;
  4.   s: string;
  5. begin
  6.   s := IntToStr(Value);
  7.  
  8.   c := length(s);
  9.  
  10.   if Value < 0 then
  11.     Dec(c);
  12.  
  13.   if c mod ALen = 0 then
  14.     c := c div ALen - 1
  15.   else
  16.     c := c div ALen;
  17.  
  18.   i := length(s) - ALen * c + 1;
  19.  
  20.   while c > 0 do
  21.   begin
  22.  
  23.     insert(ASeparator, s, i);
  24.     Dec(c);
  25.  
  26.     i := i + ALen + 1;
  27.  
  28.   end;
  29.  
  30.   Result := s;
  31. end;

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   len: integer;
  4.   sep: char;
  5.   i: integer;
  6. begin
  7.  
  8.   len := 3;
  9.   sep := ' ';
  10.  
  11.   Memo1.Lines.Add(IntToStrFormat(0, sep, len));
  12.   Memo1.Lines.Add(IntToStrFormat(-1, sep, len));
  13.   Memo1.Lines.Add(IntToStrFormat(1, sep, len));
  14.   Memo1.Lines.Add(IntToStrFormat(-12, sep, len));
  15.   Memo1.Lines.Add(IntToStrFormat(12, sep, len));
  16.   Memo1.Lines.Add(IntToStrFormat(-123, sep, len));
  17.   Memo1.Lines.Add(IntToStrFormat(123, sep, len));
  18.   Memo1.Lines.Add(IntToStrFormat(-1234, sep, len));
  19.   Memo1.Lines.Add(IntToStrFormat(1234, sep, len));
  20.   Memo1.Lines.Add(IntToStrFormat(-12345, sep, len));
  21.   Memo1.Lines.Add(IntToStrFormat(12345, sep, len));
  22.   Memo1.Lines.Add(IntToStrFormat(-123456789, sep, len));
  23.   Memo1.Lines.Add(IntToStrFormat(123456789, sep, len));
  24.  
  25.   Memo1.Lines.Add(IntToStrFormat($8000000000000000, sep, len));
  26.   Memo1.Lines.Add(IntToStrFormat($7FFFFFFFFFFFFFFF, sep, len));
  27.  
  28.  
Title: Re: IntToStr with national convention?
Post by: Kays on August 03, 2020, 03:15:29 pm
I like to write expressions if possible. They are usually easier to understand than actually having to think like a computer, “iterating” through the source code lines. So:
Code: Pascal  [Select][+][-]
  1. {$mode objFPC}
  2. {$longStrings on}
  3.  
  4. uses
  5.         math;
  6.  
  7. resourceString
  8.         groupSeparator = ',';
  9.  
  10. function groupedIntegerImage(const x: nativeUInt): string;
  11. var
  12.         /// temporarily stores the length of the result string
  13.         n: nativeUInt;
  14.         /// allows to choose between strings based on a Boolean expression
  15.         separatorOption: array[Boolean] of string;
  16. begin
  17.         // initial conversion to string
  18.         str(x, result);
  19.        
  20.         n := length(result);
  21.         // separating a single thousands digit is not recommended
  22.         // thus we start at values 10,000 and above.
  23.         if n > 4 then
  24.         begin
  25.                 separatorOption[false] := '';
  26.                 separatorOption[true] := groupSeparator;
  27.                
  28.                 result :=
  29.                         result[max(1, n-20)..max(0, n-18)] + separatorOption[n>18] +
  30.                         result[max(1, n-17)..max(0, n-15)] + separatorOption[n>15] +
  31.                         result[max(1, n-14)..max(0, n-12)] + separatorOption[n>12] +
  32.                         result[max(1, n-11)..max(0, n-9)] + separatorOption[n>9] +
  33.                         result[max(1, n-8)..max(0, n-6)] + separatorOption[n>6] +
  34.                         result[max(1, n-5)..n-3] + groupSeparator +
  35.                         result[n-2..n];
  36.         end;
  37. end;
There’s probably a nicer way to retrieve sub-strings and I deliberately avoided the “problem” of the negative sign, because I just wanted to show the principle.
Title: Re: IntToStr with national convention?
Post by: Thaddy on August 03, 2020, 06:41:10 pm
Why not try write/writeln/writestr with the formatting options already available, instead of any superfluous formatxxx()  calls?
See last part of https://www.freepascal.org/docs-html/rtl/system/write.html (the manual)
As long as the installed OS conforms to what is demanded, then the formatting is automatically correct.
Title: Re: IntToStr with national convention?
Post by: winni on August 03, 2020, 06:51:27 pm

Sorry, but I just couldn't resist posting that.
...
So, no hard feelings I hope?

Bart

Hi!

No hard feeling!

But when I read those speed junkies I don 't know: Laughing or crying?

But  they should be set in front of an Apple II and then  code the sieve of Erastotenes -
Only from 1 to 32767. It was so awful slow, that you never  knew if it is still working.
Or if you had send it in an endless loop.
That is the experience they miss.
So much for that.

You write:
Some national thousandseparators are not single byte (at least not when you use Lazarus, where evrything is UTF8).
I only know separators out of ASCII:

.,;:-/\#$

Or do need a special separator for Disney-Land??

🚦😈🧲👀🚬🤖


Something like that?

Winni
Title: Re: IntToStr with national convention?
Post by: Kays on August 03, 2020, 07:42:48 pm
[…]I only know separators out of ASCII:[…]
Well, there’s the recommendation (https://en.wikipedia.org/wiki/Decimal_separator#Digit_grouping) to use U+2009 “thin space”.
Title: Re: IntToStr with national convention?
Post by: winni on August 03, 2020, 08:06:07 pm
Well, there’s the recommendation (https://en.wikipedia.org/wiki/Decimal_separator#Digit_grouping) to use U+2009 “thin space”.

Thanx - I didn't know that.

But the situation is quiet confusing:

* If we work with ISO 31-0 we take a national separator of the well know ASCII signs - including #32. Then we don't need the "thin space"

*If we work with the recommendation for the "thin space" - that superseeds ISO 31-0 - then we don't need the other ASCII-sign anymore.

In the end there will not only be the confusion with the national signs but plus the "thin space".

But as we don't want to win a typography contest we , can take the "normal space".

Winni
Title: Re: IntToStr with national convention?
Post by: Bart on August 03, 2020, 10:20:49 pm
Or do need a special separator for Disney-Land??
🚦😈🧲👀🚬🤖

See for example https://bugs.freepascal.org/view.php?id=26803 (https://bugs.freepascal.org/view.php?id=26803).
Quote
e.g. the Slovak date separator is 2 chars: a dot followed by a space

Also as an example ThousandSeparator can be U+00AO (non-breaking space), which in UTF-8 is represented by more than 1 byte.

Bart
Title: Re: IntToStr with national convention?
Post by: Bart on August 07, 2020, 10:11:45 pm
Slightly adapted to accept vlaues and separators of any length.

Code: Pascal  [Select][+][-]
  1. function InsertThousandSep(const ValueS, AThousandSep: String): String;
  2. var
  3.   MaxLen, ResPos, SLen, i, j: Integer;
  4. begin
  5.   Result := '';
  6.   SLen := Length(ValueS);
  7.   MaxLen := SLen + ((SLen - 1) div 3) * Length(AThousandSep); //Max needed seps = ((SLen - 1) div 3)
  8.   SetLength(Result, MaxLen);
  9.   ResPos := MaxLen;
  10.   for i := Length(ValueS) downto 1 do
  11.   begin
  12.     if (SLen <> i) and ((SLen-i) mod 3 = 0) then
  13.     begin
  14.       for j := Length(AThousandSep) downto 1 do
  15.       begin
  16.         Result[ResPos] := AThousandSep[j];
  17.         Dec(ResPos);
  18.       end;
  19.     end;
  20.     Result[ResPos] := ValueS[i];
  21.     Dec(ResPos);
  22.   end;
  23. end;

(And a full 1% faster than my previous effort, yeah... )

Bart
Title: Re: IntToStr with national convention?
Post by: marcov on August 07, 2020, 10:44:21 pm
Awful slow.

0.000569  Milliseconds. Awful slow.

Each. How many integers are there in a database dump?

Anyway, I don't think it would be wise to change inttostr, changing that now would break too much, since most integer->string conversions are probably not for presentation/gui purposes,  just make a different one with a different name for internationalized versiosn
Title: Re: IntToStr with national convention?
Post by: winni on August 07, 2020, 11:02:48 pm

Each. How many integers are there in a database dump?


1:  0.000569  = ~ 1757 per milisecond
                       =    1 757 000 per second

Enough for your DB?

First compute, then whine.

Winni
Title: Re: IntToStr with national convention?
Post by: marcov on August 07, 2020, 11:07:03 pm
                       =    1 757 000 per second

20 on a row, 87000 rows. And that even is at full CPU, and I assume the database also has other things to do than converting integers. Like, shudder, floats :_)

Quote
Enough for your DB?

First compute, then whine.

First think if a value is useful, then compute it.
Title: Re: IntToStr with national convention?
Post by: winni on August 07, 2020, 11:17:06 pm
Hi!

The most time in a database dump is used by the I/O process to wait until ready - even with a cached Linux disc.

Winni
Title: Re: IntToStr with national convention?
Post by: marcov on August 08, 2020, 12:15:12 am
The most time in a database dump is used by the I/O process to wait until ready - even with a cached Linux disc.

For binary dumping maybe. For textual output it is usually easily measurable. 
Title: Re: IntToStr with national convention?
Post by: Bart on August 08, 2020, 10:23:00 am
Anyway, I don't think it would be wise to change inttostr, changing that now would break too much, since most integer->string conversions are probably not for presentation/gui purposes,  just make a different one with a different name for internationalized versiosn

FWIW: It was never my intention to have this (or similar) submitted as a change/overload for the default IntToStr() we already have.
I'ts just a convenience routing for TS.

I might be tempted to have it as an optional feature in Lazarus' TSpinEditEx (and even then it probably will not be visible in the interface).

And again: all my comments about speed: regard them as irrelevant to the topic at hand.

Bart
TinyPortal © 2005-2018