0

I use the older functions Str and Val to write and read values that need to be persistent across different locales, but can you instruct Str to always format a floating point number in scientific format?

I.e I want all floating point numbers to be formatted this way and fit inside 16 characters:

-1.234567890E-34

(2 digits is sufficient for the exponent). This maximizes precision and dynamic range for a given storage size.

rossmcm
  • 5,493
  • 10
  • 55
  • 118
  • 3
    The *correct* way to deal with locale independence is to use RTL parsing/formatting functions that accept `TFormatSettings` (introduced in Delphi 7) as input, such as `Format()` and `StrToFloat()` .Then you can specify your own consistent formats that are not affected by external locales. – Remy Lebeau Feb 12 '15 at 03:23
  • Thanks @Remy. I was looking to extending the existing routine that uses `Str`, but if there is no way to do that I will use the `TFormatSettings` approach. – rossmcm Feb 12 '15 at 03:47
  • You cannot change how `Str()` formats its output. You can tell it the desired number of decimal places for floating-point numbers, but that is all you can do. `Format()` and `FloatToStr()` are more flexible. – Remy Lebeau Feb 12 '15 at 04:03

0 Answers0