1. 程式人生 > >【LoadRunner】解決指令碼中字元型轉浮點型或由浮點型轉字元型

【LoadRunner】解決指令碼中字元型轉浮點型或由浮點型轉字元型

double atof( const char *string);  //申明函式


Action()

        float UpPrice1;
        float i=0.1;
        char* price1=(char*)calloc(100,sizeof(char));  //請求儲存空間

//Correlation comment - Do not change!Original value='7.89' Name ='CorrelationParameter_2'

 web_reg_save_param_ex(
      "ParamName=CorrelationParameter_2",
      "LB=UpPrice\":",
      "RB=,",
      LAST);

 web_submit_data("PersonalMarketHandler.ashx_17",
      "Action=http://{URL}/Handlers/Default/StockMarket/PersonalMarketHandler.ashx/?method=GetDefaultWarningOfCode",
      "Method=POST",
      "RecContentType=text/plain",
      "Referer=http://{URL}/Pages/Default/Home/MatchIndex.aspx?TraderID={CorrelationParameter_1}",
      "Snapshot=t219.inf",
      "Mode=HTTP",
       ITEMDATA,
       "Name=code", "Value={code}", ENDITEM,
  LAST);

 lr_save_string(lr_eval_string ("{CorrelationParameter_2}"),"UpPrice"); //將關聯的字串值存入引數變數UpPrice中

 UpPrice1=atof(lr_eval_string ("{UpPrice}"))+i;   //將字串的UpPrice轉換為float,並將float值相加

 sprintf(price1,"%.2f",UpPrice1); // 將float轉換為string

 lr_save_string(price1,"price"); //將轉換的字串值存入引數變數price中

 lr_error_message (":%s",lr_eval_string ("{price}"));

 web_submit_data("PersonalMarketHandler.ashx_19",
       "Action=http://{URL}/Handlers/Default/StockMarket/PersonalMarketHandler.ashx/?method=AddOrUpdateWarningCode",
        "Method=POST",
       "RecContentType=text/plain",
       "Referer=http://{URL}/Pages/Default/Home/MatchIndex.aspx?TraderID={CorrelationParameter_1}",
       "Snapshot=t221.inf",
       "Mode=HTTP",
        ITEMDATA,
       "Name=id", "Value=0", ENDITEM,
       "Name=code", "Value={code}", ENDITEM,
       "Name=upPrice", "Value={price}", ENDITEM,
       "Name=downPrice", "Value={CorrelationParameter_3}", ENDITEM,
  LAST);

     free(price1);

return 0;
}