ExCtrls/TFloatSISpinEditEx: Supports more prefixes (binary as well as some metric).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9567 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2025-01-06 22:57:12 +00:00
parent 8fe8d3a882
commit 073231eb50

View File

@ -182,8 +182,10 @@ type
{ TCustomFloatSISpinEdit (Author: Bart Broersma) }
TSIPrefix = (Yotta,Zetta,Exa,Peta,Tera,Giga,Mega,kilo,kiloUC,One,
milli,micro,microU,microalt,nano,pico,femto,atto,zepto,yocto);
TSIPrefix = ( // see: https://en.wikipedia.org/wiki/Metric_prefix, https://en.wikipedia.org/wiki/Binary_prefix
Quetta, Ronna, Yobi, Yotta, Zebi, Zetta, Exbi, Exa, Pebi, Peta, Tebi, Tera, Gibi, Giga, Mebi, Mega, Kibi, kilo, kiloUC, hecto, deca, One,
deci, centi, milli, micro, microU, microalt, nano, pico, femto, atto, zepto, yocto, ronto, quecto
);
{ TCustomFloatSISpinEditEx }
@ -296,12 +298,20 @@ const
AllowedControlChars = [#8, #9, ^C, ^X, ^V, ^Z];
SIPrefixes: array[TSIPrefix] of String = (
'Y', 'Z', 'E', 'P', 'T', 'G', 'M', 'k', 'K', '',
'm', 'µ', 'mc', 'u', 'n', 'p', 'f', 'a', 'z', 'y'
'Q', 'R', 'Yobi', 'Y', 'Zobi', 'Z', 'Ebi', 'E', 'Pebi', 'P', 'Tebi', 'T', 'Gibi', 'G', 'Mebi', 'M', 'Kibi', 'k', 'K', 'h', 'de', '',
'd', 'c', 'm', 'µ', 'mc', 'u', 'n', 'p', 'f', 'a', 'z', 'y', 'r', 'q'
);
_1024_1 = 1024.0;
_1024_2 = _1024_1*_1024_1;
_1024_3 = _1024_1*_1024_2;
_1024_4 = _1024_2*_1024_2;
_1024_5 = _1024_2*_1024_3;
_1024_6 = _1024_3*_1024_3;
_1024_7 = _1024_3*_1024_4;
_1024_8 = _1024_4*_1024_4;
SIFactors: array[TSIPrefix] of Double = (
1E+24, 1E+21, 1E+18, 1E+15, 1E+12, 1E+9, 1E+6, 1E+3, 1E+3, 1.0,
1E-3, 1E-6, 1E-6, 1E-6, 1E-9, 1E-12, 1E-15, 1E-18, 1E-21, 1E-24
1E+30, 1E+27, _1024_8, 1E+24, _1024_7, 1E+21, _1024_6, 1E+18, _1024_5, 1E+15, _1024_4, 1E+12, _1024_3, 1E+9, _1024_2, 1E+6, _1024_1, 1E+3, 1E+3, 1E+2, 1E+1, 1.0,
1E-1, 1E-2, 1E-3, 1E-6, 1E-6, 1E-6, 1E-9, 1E-12, 1E-15, 1E-18, 1E-21, 1E-24, 1E-27, 1E-30
);
function UTF8EndsStr(const ASubStr, AStr: string): Boolean;
@ -610,7 +620,7 @@ begin
{$ELSE}
fs := GetFormatSettings;
{$IFEND}
//since Ord(micro) < Ord(micoralt) this will alway render with a decent mu ('µ') and not with 'mc'
//since Ord(micro) < Ord(microalt) this will alway render with a decent mu ('µ') and not with 'mc'
Result := FloatToStrF(LValue/Factor, ffFixed, 20, DecimalPlaces, fs) + SIPrefixes[Prefix];
Exit;
end;