~~~~~BT的ASP~~~~~~~

xiaoyuehen 2008-12-03 11:29:47
option explicit

dim tmpGetmoney

tmpGetmoney = 0.58
response.write("*: " & tmpGetmoney * 100)
response.write("<br>")
response.write("fix: " & fix(tmpGetmoney * 100))
response.write("<br>")
tmpGetmoney = fix(tmpGetmoney * 100) / 100
response.write("tmpGetmoney: " & tmpGetmoney)
response.write("<br>")
response.write("formatnumber: " & formatnumber(tmpGetmoney, 2, true, false, false))
response.write("<br>")


只在 0.58, 0.57 才出现这种情况..无语~!
...全文
147 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoyuehen 2008-12-31
  • 打赏
  • 举报
回复
alan817 的测试太酷了.呵呵^^
xiaoyuehen 2008-12-31
  • 打赏
  • 举报
回复
谢谢各位参与..这里只是想说明 Fix 这个函数的BT..因为按帮助说这个函数是会把小数干掉的..但是从我给的例子上看又不完全是这样..出乎意料了.(或许是因为vbs本身的问题..0.58 * 100 后可能是 57.99999吧)
toury 的回复这里没有考虑到 0.586 的情况...因为这里的原意是使用fix所述的功能.
toury 2008-12-03
  • 打赏
  • 举报
回复
关键在这里:intTemp = CInt(tmpGetmoney * 100)而不是intTemp = tmpGetmoney * 100
toury 2008-12-03
  • 打赏
  • 举报
回复

<%
Dim tmpGetmoney, intTemp

tmpGetmoney = 0.58
response.write ("*: " & tmpGetmoney * 100)
response.write (" <br>")
intTemp = CInt(tmpGetmoney * 100)
response.write intTemp
response.write ("fix: " & Fix(intTemp))
response.write (" <br>")
tmpGetmoney = Fix(intTemp) / 100
response.write ("tmpGetmoney: " & tmpGetmoney)
response.write (" <br>")
response.write ("formatnumber: " & FormatNumber(tmpGetmoney, 2, True, False, False))
response.write (" <br>")

%>

注意强制类型转换就可以了
alan817 2008-12-03
  • 打赏
  • 举报
回复
不知道是什么原因,希望有元老来解释给我们听听
layers2323 2008-12-03
  • 打赏
  • 举报
回复
有解释吗?
virgo2008 2008-12-03
  • 打赏
  • 举报
回复
汗,BT!
alan817 2008-12-03
  • 打赏
  • 举报
回复
测试情况


单独赋值:tmpGetmoney = .58
*: 58
fix: 57
tmpGetmoney: .57
formatnumber: 0.57



以下是循环*************************************************************************
tmpGetmoney = .01
*: 1
fix: 1
tmpGetmoney: .01
formatnumber: 0.01
======================================================================
tmpGetmoney = .02
*: 2
fix: 2
tmpGetmoney: .02
formatnumber: 0.02
======================================================================
tmpGetmoney = .03
*: 3
fix: 3
tmpGetmoney: .03
formatnumber: 0.03
======================================================================
tmpGetmoney = .04
*: 4
fix: 4
tmpGetmoney: .04
formatnumber: 0.04
======================================================================
tmpGetmoney = .05
*: 5
fix: 5
tmpGetmoney: .05
formatnumber: 0.05
======================================================================
tmpGetmoney = .06
*: 6
fix: 6
tmpGetmoney: .06
formatnumber: 0.06
======================================================================
tmpGetmoney = .07
*: 7
fix: 7
tmpGetmoney: .07
formatnumber: 0.07
======================================================================
tmpGetmoney = .08
*: 8
fix: 8
tmpGetmoney: .08
formatnumber: 0.08
======================================================================
tmpGetmoney = .09
*: 9
fix: 9
tmpGetmoney: .09
formatnumber: 0.09
======================================================================
tmpGetmoney = .1
*: 10
fix: 10
tmpGetmoney: .1
formatnumber: 0.10
======================================================================
tmpGetmoney = .11
*: 11
fix: 10
tmpGetmoney: .1
formatnumber: 0.10
======================================================================
tmpGetmoney = .12
*: 12
fix: 11
tmpGetmoney: .11
formatnumber: 0.11
======================================================================
tmpGetmoney = .13
*: 13
fix: 12
tmpGetmoney: .12
formatnumber: 0.12
======================================================================
tmpGetmoney = .14
*: 14
fix: 13
tmpGetmoney: .13
formatnumber: 0.13
======================================================================


………………


tmpGetmoney = .48
*: 48
fix: 48
tmpGetmoney: .48
formatnumber: 0.48
======================================================================
tmpGetmoney = .49
*: 49
fix: 49
tmpGetmoney: .49
formatnumber: 0.49
======================================================================
tmpGetmoney = .5
*: 50
fix: 50
tmpGetmoney: .5
formatnumber: 0.50
======================================================================
tmpGetmoney = .51
*: 51
fix: 51
tmpGetmoney: .51
formatnumber: 0.51
======================================================================
tmpGetmoney = .52
*: 52
fix: 52
tmpGetmoney: .52
formatnumber: 0.52
======================================================================
tmpGetmoney = .53
*: 53
fix: 53
tmpGetmoney: .53
formatnumber: 0.53
======================================================================
tmpGetmoney = .54
*: 54
fix: 54
tmpGetmoney: .54
formatnumber: 0.54
======================================================================
tmpGetmoney = .55
*: 55
fix: 55
tmpGetmoney: .55
formatnumber: 0.55
======================================================================
tmpGetmoney = .56
*: 56
fix: 56
tmpGetmoney: .56
formatnumber: 0.56
======================================================================
tmpGetmoney = .57
*: 57
fix: 57
tmpGetmoney: .57
formatnumber: 0.57
======================================================================
tmpGetmoney = .58
*: 58
fix: 58
tmpGetmoney: .58
formatnumber: 0.58
======================================================================
tmpGetmoney = .59
*: 59
fix: 59
tmpGetmoney: .59
formatnumber: 0.59
======================================================================
tmpGetmoney = .6
*: 60
fix: 60
tmpGetmoney: .6
formatnumber: 0.60
======================================================================

………………
layers2323 2008-12-03
  • 打赏
  • 举报
回复
....
alan817 2008-12-03
  • 打赏
  • 举报
回复
确实很变态,而且是不一样的变态


测试了一下 For i=0.01 to 1 step 0.01
循环过程中的 0.58, 0.57 和单独付赋值测试的结果不一样, 而其他一些数值又出现和0.57, 0.58一样的情况



28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧