救命啊,不知道为什么2个double类型的数相除小数点前没有0!!!!(在线等)

coolfatfish 2003-03-06 02:15:41
我也不知道为什么会这样
源程序是
Private Sub cmdEquals_Click()
Dim new_value As Double

If txtDisplay.Text = "" Then
new_value = 0
Else
new_value = CDbl(txtDisplay.Text)
End If
Select Case Operator
……
Case opDivide
If new_value = 0 Then
MsgBox ("³ýÊý²»¿ÉÒÔÊÇ0")
Operator = opDivide
NoEntry = True
txtDisplay.Text = CStr(StoredValue)

Else
StoredValue = StoredValue / new_value
Operator = opNone

txtDisplay.Text = CStr(StoredValue)
NoEntry = True
End If
End Select
真是太奇怪了
以前没遇见过这种事情
是不是我text设置有问题??
...全文
367 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
MoQi_123 2003-03-06
  • 打赏
  • 举报
回复

是Format没有写好。现在试试这句(已经调试通过)

txtDisplay.Text = Format(CStr(StoredValue),"#0.00")
freezx 2003-03-06
  • 打赏
  • 举报
回复
你只好把结果转成字符型,等到拿出结果的时候再把它转成数值型再调用
coolfatfish 2003-03-06
  • 打赏
  • 举报
回复
o ,我问这问题主要是在给一个ppmm做计算器作业时候在text里显示时候遇见的
然后呢
10分钟后就解决了
只是考虑正负后"0"&就解决了
用户 昵称 2003-03-06
  • 打赏
  • 举报
回复
Public Function FormatStr(InputNumber) As String
'┏━━━━━━━━━┓
'┃格式化字符串,保留
'┃小数点后四位
'┃11位长度
'┗━━━━━━━━━┛
On Error GoTo ErrHandle
Dim flAg As Boolean
Dim a As String
Dim I As Integer

a = ""
flAg = False

If Abs(CInt(InputNumber) - InputNumber) <= 0.00001 Then
InputNumber = CInt(InputNumber)
flAg = True
End If
If flAg Then
If Abs(InputNumber) <= 0.00001 Then
InputNumber = 0
End If
a = LTrim(RTrim(str(InputNumber))) + ".0000"
a = String(11 - Len(a), " ") & a
FormatStr = a
Exit Function
Else
a = str(Format(InputNumber, fm))
For I = 1 To Len(a)
If Mid(a, I, 1) = "." Then
Exit For
End If
Next I
I = Len(a) - I
If I <= 0 Then
a = a & ".0000"
a = String(11 - Len(a), " ") & a
FormatStr = a

Exit Function
End If
a = a + String((4 - I), "0")
If (Abs(InputNumber) < 1 And InputNumber > 0) Then
a = "0" + LTrim(a)
End If
If (Abs(InputNumber) < 1 And InputNumber < 0) Then
a = "-0" + Mid$(a, 2)
End If
End If
If (Abs(InputNumber - 0) <= 0.00001) Then
a = "0.0000"
End If
a = String(11 - Len(a), " ") & a
FormatStr = a
Exit Function
ErrHandle:
Err = 0
FormatStr = str(Format(InputNumber, "#0.0000"))
End Function
xinjiana 2003-03-06
  • 打赏
  • 举报
回复
我也遇到同样的问题,设置format好像没什么用,

是不会影响计算,但是看起来难过啊

期待结果
qiqif 2003-03-06
  • 打赏
  • 举报
回复
vb里本来就是这样的
如0.1就显示为.1
不会影响计算
xayzmb 2003-03-06
  • 打赏
  • 举报
回复
小数点前没有零?什么意思.
Girl1983 2003-03-06
  • 打赏
  • 举报
回复
也没通过,关注这个问题
Girl1983 2003-03-06
  • 打赏
  • 举报
回复
可以设置DataFormat
lxcc 2003-03-06
  • 打赏
  • 举报
回复
format格式化一下数据
str=format(cal,"0.00")
Sean918 2003-03-06
  • 打赏
  • 举报
回复
前加 #
northwolves 2003-03-06
  • 打赏
  • 举报
回复
Private Sub command1_Click()
Dim x As Double
Dim y As Double
x = 1.3
y = 0.7
MsgBox IIf(x / y > 1, x / y, Format(x / y, "0" & x / y))
End Sub

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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