[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

To set Format a numberic string value

Posted on 2005-05-05
11
Medium Priority
?
194 Views
Last Modified: 2010-04-05

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

0
Comment
Question by:namcit99
  • 6
  • 3
  • 2
11 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 80 total points
ID: 13941886
   var
        f: double;
    begin
        edit1.text := formatfloat('#,###', 123456); // returns "123,456"

        f := StrToFloat( StringReplace(edit1.text, ',', '', [rfReplaceAll])); // returns 123456

        edit2.text := floattostr(f);
    end;
0
 

Author Comment

by:namcit99
ID: 13942057

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
0
 

Author Comment

by:namcit99
ID: 13942078

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
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:namcit99
ID: 13942436

lcdaung   :=  Formatfloat('#,###', Dkdmnv.ADOQrydmnv.FieldByName('Daung').AsInteger)    ;

updatedmnv.txtdaung.Text    := IFThen(lcdaung='', '0', lcdaung)   ;

Any more good way ? Too long command
0
 

Author Comment

by:namcit99
ID: 13942465

I should write two command to get the lastest result
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13943848
Integer to string

FloatToStrF(iTemp, ffNumber, 9, 0)  // just change the 9 part to a large enough number for the values you pass in
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13943857
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
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 13955296
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 ''
0
 

Author Comment

by:namcit99
ID: 13956249

Two ways are good. I want to accept two comment. But i could not find out "Split" link
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13959311
When you accept an answer, the next screen allows you to split the points and choose more people.
0
 

Author Comment

by:namcit99
ID: 13964609

Thank for all consider
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question