Rave - Alinhando uma coluna de numeros com ponto decimal |
Top Previous Next |
|
Tip #1 - Aligning a column of numbers on the decimal point
Category Code Based - General
Question
How do I align a column of numbers on the decimal point?
Solution
The secret to this task is understanding that after a print command, no matter the justification (left, right or center), ReportPrinter always leaves the text cursor at the end of the text just printed.
Knowing this, we can split the text into two pieces, in this case the first half will contain the digits up to and including the decimal point and the second half will contain the digits after the decimal point. Then we right justify print the first half then left justify print the second half. Using tab columns (as in the example below) we would set the justification to pjRight and set the margin to the distance we want the decimal point from the right side of the tab box.
You must make sure to print the second half of the number in a separate print statement from the first half (that contains the tab character, #9) otherwise the whole number will be right justified.
Example:
{ The margin is set to 50/100ths of an inch which means the decimal point will appear 0.5 inches from the right side of the tab box }
ClearTabs;
SetTab(1.0,pjRight,1.5,50,BOXLINEALL,0); While (LinesLeft > 0) and not Table1.EOF do begin S1 := NumberField.AsString; I1 := Pos('.',S1); { Find position of the decimal point } If I1 = 0 then begin { There is no decimal point } I1 := Length(S1); { Print whole string on first Print() } end; { if } Print(#9 + Copy(S1,1,I1 - 1); { Print the first half } Print(Copy(S1,I1,Length(S1) - I1 + 1); { Second half } Table1.Next; end; { while } Result := not Table1.EOF;
|