這條運算公式該怎麼改呢? |
答題得分者是:P.D.
|
lovemari
中階會員 發表:134 回覆:224 積分:76 註冊:2005-08-18 發送簡訊給我 |
小弟寫下列算式的時候 跑出 "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 發送簡訊給我 |
|
st33chen
尊榮會員 發表:15 回覆:591 積分:1201 註冊:2005-09-30 發送簡訊給我 |
------
IS IT WHAT IT IS 我是 李慕白 請倒著唸. 又想把老話拿出來說, 請用台語發音 : 專家專家全是ROBOT CAR (滷肉腳啦); 都已接手這麼久了, 績效還是那麼爛, 講話還那麼大聲. |
P.D.
版主 發表:603 回覆:4038 積分:3874 註冊:2006-10-31 發送簡訊給我 |
我非常不建議你這樣的寫法(紅色段)
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 發送簡訊給我 |
簡單明暸
===================引 用 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 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |