線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1112
推到 Plurk!
推到 Facebook!

這條運算公式該怎麼改呢?

答題得分者是:P.D.
lovemari
中階會員


發表:134
回覆:224
積分:76
註冊:2005-08-18

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-04-15 17:24:08 IP:122.116.xxx.xxx 訂閱


小弟寫下列算式的時候
跑出

"is not a valid floating point value"

也試過Intger 但有值有小數點也不行
請問我該怎麼改呢?


[code delphi]
With StringGrid11 do
begin
RowCount := RowCount 1;
Cells[1,RowCount-1] := Fieldbyname('工單').AsString;
Cells[7,RowCount-1] := Fieldbyname('已上傳ERP工時').AsString;
StringGrid11.Cells[8,RowCount-1] := FloattoStr(StrTofloat(StringGrid11.Cells[7,RowCount-1]) - (StrToFloat(StringGrid11.Cells[6,RowCount-1])));
END;

[/code]
------
Program : Delphi 7
DataBase : Oracle 9i
Client : ClientDataSet
小傑克
資深會員


發表:5
回覆:209
積分:357
註冊:2009-02-16

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-04-15 17:47:51 IP:59.112.xxx.xxx 訂閱
這需要debug ,錯誤有可能是空白引起的
------
額有朝天骨,眼中有靈光
st33chen
尊榮會員


發表:15
回覆:591
積分:1201
註冊:2005-09-30

發送簡訊給我
#3 引用回覆 回覆 發表時間:2009-04-15 18:21:58 IP:122.116.xxx.xxx 未訂閱
------
IS IT WHAT IT IS
我是 李慕白 請倒著唸.
又想把老話拿出來說, 請用台語發音 : 專家專家全是ROBOT CAR (滷肉腳啦);
都已接手這麼久了, 績效還是那麼爛, 講話還那麼大聲.
P.D.
版主


發表:603
回覆:4038
積分:3874
註冊:2006-10-31

發送簡訊給我
#4 引用回覆 回覆 發表時間:2009-04-17 18:38:11 IP:61.67.xxx.xxx 未訂閱
我非常不建議你這樣的寫法(紅色段)
strtofloat(xxxx), 若 xxx 裡面的字串值不符合 strtofloat 的要求, 就會引發你所提到的問題, 而且 strtofloat 也會觸發debug 錯誤, 所以建議你用兩組變數來代表
try
a1:= StrTofloat(StringGrid11.Cells[7,RowCount-1)
except
a1:= 0;
end;
依此類推, 定出 a2 值
最後再如下, 就肯定不會有問題了
StringGrid11.Cells[8,RowCount-1] := floattostr(a1-a2);

===================引 用 lovemari 文 章===================
[code delphi]
With StringGrid11 do
begin
RowCount := RowCount 1;
Cells[1,RowCount-1] := Fieldbyname('工單').AsString;
Cells[7,RowCount-1] := Fieldbyname('已上傳ERP工時').AsString;
StringGrid11.Cells[8,RowCount-1] := FloattoStr(StrTofloat(StringGrid11.Cells[7,RowCount-1]) - (StrToFloat(StringGrid11.Cells[6,RowCount-1])));
END;

[/code]
lovemari
中階會員


發表:134
回覆:224
積分:76
註冊:2005-08-18

發送簡訊給我
#5 引用回覆 回覆 發表時間:2009-04-20 08:11:24 IP:122.116.xxx.xxx 訂閱
簡單明暸


===================引 用 P.D. 文 章===================
我非常不建議你這樣的寫法(紅色段)
strtofloat(xxxx), 若 xxx 裡面的字串值不符合 strtofloat 的要求, 就會引發你所提到的問題, 而且 strtofloat 也會觸發debug 錯誤, 所以建議你用兩組變數來代表
try
a1:= StrTofloat(StringGrid11.Cells[7,RowCount-1)
except
a1:= 0;
end;
依此類推, 定出 a2 值
最後再如下, 就肯定不會有問題了
StringGrid11.Cells[8,RowCount-1] := floattostr(a1-a2);

===================引 用 lovemari 文 章===================
[code delphi]
With StringGrid11 do
begin
RowCount := RowCount 1;
Cells[1,RowCount-1] := Fieldbyname('工單').AsString;
Cells[7,RowCount-1] := Fieldbyname('已上傳ERP工時').AsString;
StringGrid11.Cells[8,RowCount-1] := FloattoStr(StrTofloat(StringGrid11.Cells[7,RowCount-1]) - (StrToFloat(StringGrid11.Cells[6,RowCount-1])));
END;

[/code]
------
Program : Delphi 7
DataBase : Oracle 9i
Client : ClientDataSet
系統時間:2024-05-19 14:19:02
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!