QUESTION: Hi Randy,
At one point- my program either multiplies or divides (User's choice) two real numbers and then displays the result in an edit box. Formatfloat is used like this to show two decimal places
The code to do this is contained in a button's onclick event.
The Edit box displays the result properly the first time the button is clicked and usually the second time as well. further clicks make the display show 3 decimal places and more.
I can understand the number before the decimal point increasing but I thought that the formatting would prevent the display showing more than 2 decimal places.
Hope I've explained this properly and if so Can it be cured?
I tried to review the source code for FormatFloat, but it calls an assembly routine, and I don't have the patience to debug it... This is the routine that I use to impersonate that same output:
function RtoC(Source: Double; S,D: integer; ZeroSuppress: Boolean=False): string;
Var TStr: string;
if ZeroSuppress and (Source=0) then TStr:=Spc(S);
This is how you would use it in that case:
The S parameter specifies the padding. Zero padding does not add any padding to the text. The D parameter specifies the number of decimal places.
[an error occurred while processing this directive]---------- FOLLOW-UP ----------
QUESTION: Thanks Brian,
I have a few Delphi versions on my Computers and unfortunately the program I need
help on is in a Delphi 2 timewarp. That's because it contains some third party
components in DCU form only so I can't upgrade it.
The Delphi 2 compiler complains about boolean variable being initialised in your
Functions declaration although I suppose that can be overcome.
It also doesn't recognise the SPC function used.
Can this be modified to work in D2?
if that's the case, I'd reduce the function to
function RtoC(Source: Double; S,D: integer): string;
Var TStr: string;
The only thing you loose is that if the number is zero, it will output 0.00 instead of having the option of an empty string when the number is zero.