資料庫應用~小數點、無條件捨去之問題 |
答題得分者是:Stallion
|
monok
一般會員 ![]() ![]() 發表:1 回覆:2 積分:0 註冊:2004-06-27 發送簡訊給我 |
|
Stallion
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
在DBGrid的OnDrawColumnCell裡面加入下面程式碼看看。
<textarea cols="60" rows="10" class="delphi" name="code">
var
aFloatStr:String;
begin
if SameText(Column.FieldName, '選擇顯式的欄位名稱') then
begin
aFloatStr := Format('%.2f',[Column.Field.AsFloat]);
DBGrid1.Canvas.FillRect(Rect);
DBGrid1.Canvas.TextRect(Rect, Rect.Left 2, Rect.Top 2, aFloatStr);
end;
end;
</textarea>
|
monok
一般會員 ![]() ![]() 發表:1 回覆:2 積分:0 註冊:2004-06-27 發送簡訊給我 |
|
BOSS
中階會員 ![]() ![]() ![]() 發表:70 回覆:79 積分:64 註冊:2006-11-01 發送簡訊給我 |
<textarea class="delphi" rows="10" cols="60" name="code">
function TForm1.Round45(Val: Extended; Digit: ShortInt;
tp: byte): Extended;
var
Sign: ShortInt;
Tmp, LFractor: Currency;
begin
if Val >= 0 then
Sign := 1
else
Sign := -1; LFractor := Power(10, Digit);
Tmp := Val * LFractor;
if tp=0 then //四捨五入
begin
if Tmp - Round(Tmp) = 0.5 * Sign then
Tmp := Tmp 0.01 * Sign;
Tmp := Round(Tmp);
end
else if tp=1 then //無條件捨去
Tmp := Int(Tmp)
else if Tmp-Int(Tmp)<>0 then //無條件進位
Tmp := Int(Tmp) 1 * Sign; Result := Tmp / LFractor; end;
再套用Stallion大大的程式
var
aFloatStr:String;
Tmp: Extended;
begin
if SameText(Column.FieldName, '選擇顯式的欄位名稱') then
begin
//aFloatStr := Format('%.2f',[Column.Field.AsFloat]);
Tmp:=Round45(Column.Field.AsFloat,2,1);
DBGrid1.Canvas.FillRect(Rect);
DBGrid1.Canvas.TextRect(Rect, Rect.Left 2, Rect.Top 2, FloatToStr(Tmp));
end;
end
</textarea>
|
monok
一般會員 ![]() ![]() 發表:1 回覆:2 積分:0 註冊:2004-06-27 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |