Vbscript asp经典格式数字竞价脚本

Vbscript asp经典格式数字竞价脚本,vbscript,asp-classic,Vbscript,Asp Classic,下午, 我在玩一个我想写的小脚本。但是我在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"

下午,

我在玩一个我想写的小脚本。但是我在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,我会写“你不能出价低于当前的要价”

请告知

问候
谢恩

线路

yourBid = isNumeric(Request("bid"))
不是将有效数字存储到
yourBid
,而是将IsNumeric()函数的(booelan)结果应用于
请求(“bid”)

换行

yourBid = CDbl(Request("bid"))

并查看您的if语句是否按预期工作。然后为
请求(“投标”)添加适当的验证

这里有两个问题:

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

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

    If Round(yourBid,2) > Round(currentBid,2) Then
    
  • 编辑:校对

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

    谢谢你的回复,是的,这是我的新手错误。改变了,现在可以了。我曾经。。。如果是数字的(Reuqest.Form(“bid”),那么yourBid=CDbl(Request(“bid”)),因此booelan.cheers伙计们。
    MsgBox VarType(4)                ' 2 = vbInteger
    MsgBox VarType(FormatNumber(4))  ' 8 = vbString