Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delphi, Number

Posted on 2012-03-17
3
Medium Priority
?
503 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 2000 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

718 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