读书人

求解下面的函数?该如何解决

发布时间: 2012-02-10 21:27:42 作者: rapoo

求解下面的函数??
function MyRound(P: Double; Decimals: integer): Double;
var
s: string;
begin
s := FloatToStrF(P, ffFixed, 15, Decimals);
Result := StrToFloat(s);
end;



function IntDate(T: TDateTime): Integer;
var
Year, Month, Day: Word;
begin
DecodeDate(T, Year, Month, Day);
Result := Year * 10000 + Month * 100 + Day;
end;

[解决办法]

Delphi(Pascal) code
//p 原始浮点数//Decimals有效小数位//比如 MyRound(20.3201734,4);//返回的值为20.3202。function MyRound(P: Double; Decimals: integer): Double;var  s: string;begin  s := FloatToStrF(P, ffFixed, 15, Decimals);  Result := StrToFloat(s);end;//其它他的功能很简单只是把年月日这三个无素,组合成一个integer数字//如传入2011/12/2 而返回的是20111202//它的功能和_IntDate函数一样。function IntDate(T: TDateTime): Integer;var  Year, Month, Day: Word;begin  DecodeDate(T, Year, Month, Day);  Result := Year * 10000 + Month * 100 + Day;end;function _IntDate(T:TDateTime):Integer;var  s:string;begin  s := FormatDateTime('yyyymmdd',t);  Result := StrToInt(s);end; 

读书人网 >.NET

热点推荐