namcit99
asked on
To set Format a numberic string value
Dear advisor !
I use Delphi 2005
I want to update vlue from a Table on nuber field. I read value from number field to a Tedit. I use IntToStr() . But i want to format value like '123,456,789' . And after the user modify value , and want to covert it like '123456'. Because the SQL Command does not accept 'commas' on value.
Please show me the function or make best function for me.
what i ask : two functions. the fisrt to format value with separate charater like from '123456' to '123,456' . The second funtion to make '123,456' to '123456'
Thank for all consider
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
whether Delphi has function like IIF function in Visual FoxPro
IIF(lExpression, eExpression1, eExpression2)
if lExpression is True then it returns eExpression1. Orther case it returns eExpression2
ASKER
lcdaung := Formatfloat('#,###', Dkdmnv.ADOQrydmnv.FieldByN
updatedmnv.txtdaung.Text := IFThen(lcdaung='', '0', lcdaung) ;
Any more good way ? Too long command
ASKER
I should write two command to get the lastest result
Integer to string
FloatToStrF(iTemp, ffNumber, 9, 0) // just change the 9 part to a large enough number for the values you pass in
FloatToStrF(iTemp, ffNumber, 9, 0) // just change the 9 part to a large enough number for the values you pass in
For the string to integer I would part of your question I would use Loki's answer of
StrToFloat( StringReplace(edit1.text, ',', '', [rfReplaceAll])); // returns 123456
StrToFloat( StringReplace(edit1.text, ',', '', [rfReplaceAll])); // returns 123456
change it to be
edit1.text := formatfloat('#,##0', 123456); // returns "123,456"
the '0' acts as a placeholder and will be a zero instead of ''
edit1.text := formatfloat('#,##0', 123456); // returns "123,456"
the '0' acts as a placeholder and will be a zero instead of ''
ASKER
Two ways are good. I want to accept two comment. But i could not find out "Split" link
When you accept an answer, the next screen allows you to split the points and choose more people.
ASKER
Thank for all consider
ASKER
Your solution is good.
But there is only one unconvenient. If the number value is 0, the Formatfloat() function returns '' (empty charater). I need when 0, return '0' . Whether formatFloat does it well. show me the best way to solve exspecial case