我们的数据库中有一个值,它是一个字符串,表示一个时间值,其示例值类似于8.7698,必须将其转换为实际时间。我已经开始研究这个问题了,到目前为止我提出了这个问题:
stringvar x; //original value, string datatype ex data 9.8765, get value before decimal point
numbervar x2; //convert value before decimal into a double
stringvar xH; //Convert value before decimal back to string for concatenation
stringvar x3; //value after decimal
numbervar x4; //convert value after decimal to double and multiply by .60 for conversion
stringvar xM; //Convert value after decimal back to string for concatenation
x := left({PO_PurchaseOrderHeader.TimeUpdated}, InStr ({PO_PurchaseOrderHeader.TimeUpdated},"." ));
x2 := cdbl(x);
x3 := mid({PO_PurchaseOrderHeader.TimeUpdated}, InStr ({PO_PurchaseOrderHeader.TimeUpdated},"." ), length({PO_PurchaseOrderHeader.TimeUpdated}) - InStr ({PO_PurchaseOrderHeader.TimeUpdated},"." ));
x4 := CDbl (x3) * .60;
xH := cstr(x2);
xM := cstr(x4);
xH + ":" + xM;
它说我检查时没有错误,但报告未能从我们的软件(Sage 100)中运行,我相信这个公式存在问题。任何人都可以看到我可能搞砸了吗?谢谢!
答案 0 :(得分:0)
让我们回过头来尝试简化这个公式,因为现在很难理解它。你有很多不必要的变量和类型转换可以完全删除。尝试这样的事情:
local stringvar timeString := '9.8765'; //Example value
local stringvar hr := split(timeString,'.')[1]; //the hour value
local stringvar min := split(timeString,'.')[2]; //the fractional hour to convert to mins
//the below line concatenates the hour and the newly calculated minutes
// which is just the first two digits with necessary leading/trailing zeros
hr + ':' + totext(tonumber(min) * 0.6, '00')[1 to 2]
如果在保存公式时没有收到任何错误消息,则可能甚至不会导致报告失败。在这种情况下,您需要提供更多详细信息,说明发生了什么以及您采取了哪些调试步骤。
答案 1 :(得分:0)
Note: Below formula is used assuming number before decimal is hour and number after decimal is minute. IF this is not your requirement ignore the solution
使用以下公式
Local NumberVar a;
Local NumberVar b;
Local NumberVar c;
Local StringVar d;
c:=RoundUp(ToNumber("8.669"),2);
a:=ToNumber(Split ('8.669',"." )[1]);
b:=ToNumber(Split ('8.669',"." )[2]);
d:=Split(CStr(ToNumber(Split(Totext(c),".")[2])/60))[1];
if(ToNumber(Split(Totext(c),".")[2])<60)
then
ToText(a,0)+":"+Split(ToText(c),".")[2]
else
ToText(a+ToNumber(d),0)+":"+Split(Totext(c/60),".")[2];