1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| procedure TForm23.Button2Click(Sender: TObject);
function myconverter(astring : variant) : Double;
begin
if VarIsNull(aString) then result:=10.15
else if (not TryStrToFloat(astring,result)) then result:=0
end;
begin
Memo1.Lines.Add(format('StrToFloatDef(''200.00'',0) -> %3.2f',[StrToFloatDef('200.00',0)])); // -> 0 formatsettings d'un windows en français
Memo1.Lines.Add(format('StrToFloatDef(''200,00'',0) -> %3.2f',[StrToFloatDef('200,00',0)])); // -> 200 // formatsettings d'un windows en français
Memo1.Lines.Add(format('StrToFloatDef(''200.00'',0,Formattsettings) -> %3.2f',[StrToFloatDef('200.00',0,TFormatSettings.Create('EN-US'))])); // -> 200
Memo1.Lines.Add(format('myconverter(''200.00'',0) -> %3.2f',[myconverter('200.00')])); // 0
Memo1.Lines.Add(format('myconverter(''200,00'',0) -> %3.2f',[myconverter('200,00')]));
Memo1.Lines.Add(format('myconverter('''',0) -> %3.2f',[myconverter('')]));
Memo1.Lines.Add(format('myconverter(null,0) -> %3.2f',[myconverter(null)])); // donne valeur par defaut definie dans la fonction
end; |
Partager