Solved

Delphi, Number

Posted on 2012-03-17
3
494 Views
Last Modified: 2012-03-17
Hi I need one solution for TEdit if you have.

I need write inside tedit number and when i go onExit
number has to be formated like this:

100 >>100,00
1000 >> 1.000,00
10000 >>10.000,00
100000>>100.000,00
1000000>>1.000.000,00

and onEnter has to be formated like this
100,00 >>100,00
1.000,00 >> 1000,00
10.000,00 >>10000,00
100.000,00>>100000,00
1.000.000,00>>1000000,00


Thank you
0
Comment
Question by:hrvica5
3 Comments
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 500 total points
ID: 37732336
procedure TForm1.Edit1Enter(Sender: TObject); //100.000,00>>100000,00
begin
  TEdit(Sender).Text := StringReplace(TEdit(Sender).Text, ThousandSeparator, '', [rfReplaceAll]);
  TEdit(Sender).SelectAll;
end;

procedure TForm1.Edit1Exit(Sender: TObject);//100 >>100,00
begin
  TEdit(Sender).Text := FormatFloat('#,##0.00', StrToFloat(TEdit(Sender).Text));
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); //make sure to enter just numbers
begin
  if not(Key in ['0'..'9', ThousandSeparator, DecimalSeparator, '-', #8, #13]) then
    Key := #15;
end;

Open in new window

0
 
LVL 19

Expert Comment

by:Thommy
ID: 37732347
Use OnEnter and OnExit event of TEdit:

procedure TForm1.Edit1Enter(Sender: TObject);
begin
  TEdit(Sender).Text = FloatToStrF(StrToFloat(TEdit(Sender).Text), ffFixed, 10, 2));
end;

procedure TForm1.Edit1Exit(Sender: TObject);
begin
  TEdit(Sender).Text = FloatToStrF(StrToFloat(TEdit(Sender).Text), ffNumber, 10, 2))
end;

Open in new window

0
 

Author Closing Comment

by:hrvica5
ID: 37732370
It help a lot
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now