Converting negative paranthesis string number to negative sign string number
Every once in a while you'll come across a negative number string in the form of '(1234.56)' such as in MS Excel or other apps. This function will convert that string into a negative sign string such as '-1234.56'. Thanks to Jeff Hamblin for this code. Note: this function uses DeleteCharsFromString().
function FixParenthesisNeg(const AmntStr: string): string;
{ func to convert a parenthesis negative string number to }
{ a negative sign string number. }
{ Note: code uses DeleteCharsFromString() func. }
{ e.g. FixParenthesisNeg('(123.45)') will return '-123.45' }
{ Thanks to Jeff Hamblin for this code. Email: [email protected] }
{ Web: http://www.qtools.com } begin
Result := AmntStr;
if AmntStr <> '' then if AmntStr[1] = '(' then begin
Result := DeleteCharsFromString(AmntStr, ['(', ')']);
Result := '-' + Result;
end;
end;