Solved

Delphi, Number

Posted on 2012-03-17
3
501 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month6 days, 6 hours left to enroll

626 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