Solved

Delphi, Number

Posted on 2012-03-17
3
495 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

26 Experts available now in Live!

Get 1:1 Help Now