2014-04-16 71 views
1

下午,asp classic FormatNumber出價腳本

即時通訊使用一個小招標腳本玩即時通訊試圖寫。但即時通訊formatNumber函數有問題。

currentBid = 50.51 'from database dataType double(16,2) 
yourBid = isNumeric(Request("bid")) 

If FormatNumber(yourBid,2) > FormatNumber(currentBid,2) Then 
    Response.Write"bid successful... woop woop" 
     else 
    Response.Write"you cant bid below the current asking price" 
end if 

但如果我是申辦1000寫道: 「你不能出價低於當前要價」

請告知

問候
巴蒂爾

'Changed as advised 

currentBid = 50.51 'value from database 

If IsNumeric(Request.Form("bid")) Then 
yourBid = CDbl(Request.Form("bid")) 
end if 

回答

1

您這裏有兩個問題:

  1. 正如Ekkehard提到,IsNumeric()返回一個布爾值。要測試值是數字,然後存儲到您的變量,可以使用:

    If IsNumeric(Request("bid")) Then yourBid = CDbl(Request("bid")) 
    
  2. FormatNumber()返回一個數字的字符串表示。所以你要比較一個字符串與另一個字符串,而不是另一個。如果您需要將您的數字四捨五入到兩位小數,使用Round()函數:

    If Round(yourBid,2) > Round(currentBid,2) Then 
    

編輯:證明。

MsgBox VarType(4)    ' 2 = vbInteger 
MsgBox VarType(FormatNumber(4)) ' 8 = vbString 
1

yourBid = isNumeric(Request("bid")) 

確實不是將有效數字存儲到yourBid,但IsNumeric()函數的(booelan)結果應用於Request("bid")

行更改爲

yourBid = CDbl(Request("bid")) 

,看看你的IF語句按預期工作。然後爲Request("bid")添加適當的驗證。

+0

感謝您的回覆,雅這是我的一個新秀錯誤。現在改變了它的工作原理。我用...如果isNumeric(Reuqest.Form(「bid))然後yourBid = CDbl(Request(」bid「))因此booelan。乾杯傢伙。 – Shane