Formatting a number
I am wondering if you can help me with this:
I have a DBText field that is a float and I need to change it to a
specifically formatted String. The final format is 5 number slots and no
decimal places eg
25.25 = 02525
5.01 = 00501
100.00 = 10000
I have been playing around with FormatString and FormatTextMask, but the
only way I can get this to work is to have different cases for the general
class of number ie:
Var
x:Variant;
y:String;
begin
x := Round(Report['Permanent Impairment Percent']*100);
IF x>='1000' then
if x<='9999' then
begin
y:= FloatToStr(x);
Value:=Copy(FormatMaskText('\00000;0;0', y),0,5);
end;
x := Round(Report['Permanent Impairment Percent']*100);
IF x>='10' then
if x<='999' then
begin
y:= FloatToStr(x);
Value:=Copy(FormatMaskText('\0\0000;0;0', y),0,5);
end;
x := Round(Report['Permanent Impairment Percent']*100);
IF x='10000' then
begin
y:= FloatToStr(x);
Value:=Copy(FormatMaskText('00000;0;0', y),0,5);
end;
end;
As you can see, quite ugly! Do you have any suggestions as to how else I
can tackle this?
I have a DBText field that is a float and I need to change it to a
specifically formatted String. The final format is 5 number slots and no
decimal places eg
25.25 = 02525
5.01 = 00501
100.00 = 10000
I have been playing around with FormatString and FormatTextMask, but the
only way I can get this to work is to have different cases for the general
class of number ie:
Var
x:Variant;
y:String;
begin
x := Round(Report['Permanent Impairment Percent']*100);
IF x>='1000' then
if x<='9999' then
begin
y:= FloatToStr(x);
Value:=Copy(FormatMaskText('\00000;0;0', y),0,5);
end;
x := Round(Report['Permanent Impairment Percent']*100);
IF x>='10' then
if x<='999' then
begin
y:= FloatToStr(x);
Value:=Copy(FormatMaskText('\0\0000;0;0', y),0,5);
end;
x := Round(Report['Permanent Impairment Percent']*100);
IF x='10000' then
begin
y:= FloatToStr(x);
Value:=Copy(FormatMaskText('00000;0;0', y),0,5);
end;
end;
As you can see, quite ugly! Do you have any suggestions as to how else I
can tackle this?
This discussion has been closed.
Comments
apply a single display format to accomplish the same thing. Have you tried
experimenting with the FloatToStrF function?
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com