【问题标题】:asp classic FormatNumber bidding scriptasp经典FormatNumber出价脚本
【发布时间】:2014-04-16 14:08:37
【问题描述】:

下午,

我正在尝试编写一个小投标脚本。但是我在使用 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

【问题讨论】:

    标签: vbscript asp-classic


    【解决方案1】:

    这里有两个问题:

    1. 正如 Ekkehard 提到的,IsNumeric() 返回一个布尔值。要测试该值是否为数字然后存储到您的变量中,请使用:

      If IsNumeric(Request("bid")) Then yourBid = CDbl(Request("bid"))
      
    2. FormatNumber() 返回一个数字的 string 表示。因此,您将一个字符串与另一个字符串进行比较,而不是一个数字与另一个数字进行比较。如果您需要将数字四舍五入到小数点后两位,请改用Round() 函数:

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

    编辑:证明。

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

    【讨论】:

      【解决方案2】:

      线

      yourBid = isNumeric(Request("bid"))
      

      不会将有效数字存储到 yourBid,而是将 IsNumeric() 函数的(布尔)结果应用于 Request("bid")

      换行

      yourBid = CDbl(Request("bid"))
      

      并查看您的 IF 语句是否按预期工作。然后为Request("bid") 添加适当的验证。

      【讨论】:

      • 感谢您的回复,这是我的菜鸟错误。改变它现在它工作。我用... if isNumeric(Reuqest.Form("bid)) Then yourBid = CDbl(Request("bid")) 因此 booelan.欢呼伙计们。
      猜你喜欢
      • 1970-01-01
      • 2015-08-04
      • 1970-01-01
      • 2016-02-09
      • 1970-01-01
      • 2010-09-15
      • 1970-01-01
      • 1970-01-01
      • 2017-12-26
      相关资源
      最近更新 更多