Convert string with commas to float

前端 未结 9 2094
走了就别回头了
走了就别回头了 2021-02-19 18:58

Is there a built-in Delphi function which would convert a string such as \'3,232.00\' to float? StrToFloat raises an exception because of the comma. Or is the only way to stri

9条回答
  •  太阳男子
    2021-02-19 19:38

    Do you exactly know, that '.' is decimal separator and ',' is thousand separator (always)? If so, then you should fill the TFormatSettings record and pass it to StrToFloat.

    FillChar(FS, SizeOf(FS), 0);
    ... // filling other fields
    FS.ThousandSeparator := ',';
    FS.DecimalSeparator := '.';
    V := StrToFloat(S, FS);
    

提交回复
热议问题