Solved

Delphi, Number

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 167
find a node in VST 2 79
IP without any Dots 1 59
SQL Server Express automatically execute SQL or SP 8 35
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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