这个可能对你有点用 http://www.csdn.net/expert/topic/533/533226.xml?temp=.9201929 主 题: 怎样四舍五入? 'MainNumber是要转化的数,Number要保留的位数 Private Function CRound(MainNumber As Double, Number As Double) As Double CRound = Int(MainNumber * 10 ^ Number + 0.5) / 10 ^ Number End FunctionPrivate Sub Command1_Click() Print CRound(-3.145, 2) '3.15 End Sub
x=123456
y=mid(x,2,3)
結果:y=234
用formatnumber看看吧,用法和format几乎一样的
执行后说round函数未定义
是文本形
执行后也是说formatnumber函数未定义是不是这个函数不支持用在SQL语句里啊?
select cast(num*price as numeric(18,2)) as totalprice from book
我在ACCESS里执行就没错。
可是在程序里用CONN.execute("select ROUND(num*price,2) as totalprice from book"
)就是函数未定义
我是用ADO
是不是我那里弄错了?
后面都是零!
有效位数不变
你的方法在access里都不行!
请问在ACCESS里应该怎么做??急啊!
num是数字[册数]
price 是货币[单价]
rebate 是数字[折扣]我想求每一本书的实洋
结果这样算出来,小数有很多位。
这样所有记录求和后就有0.01到0.05的差别,可财务说不行。
如果在6.0中一般是可以的
http://www.csdn.net/expert/topic/533/533226.xml?temp=.9201929
主 题: 怎样四舍五入?
'MainNumber是要转化的数,Number要保留的位数
Private Function CRound(MainNumber As Double, Number As Double) As Double
CRound = Int(MainNumber * 10 ^ Number + 0.5) / 10 ^ Number
End FunctionPrivate Sub Command1_Click()
Print CRound(-3.145, 2) '3.15
End Sub
谢谢您。不过现在是如何才能在执行SQL语句时就已经把结果保留两位数!
在sql 中
select convert(numeric(20,2),num*price) as totalprice from book
用FORMAT函数可以,但是在报表里对TOTALPRICE这个字段求和却不行了,说丢失数据类型!