在我的程序vb.net中使用此功能
Public Function getmeter(ByVal metersize As Double) As Double
Dim result As Double
Dim remain As Double = metersize / size
SplitDouble(remain)
result = Calcuatedemeter(cartons, plateNum)
Return result
End Function
当iam赋予此值时 尺码= 1365.28 尺寸= 1.61 结果应该是848,我在我的计算器中以及在google计算器和duckduckgo计算器中的ci-calculator中对其进行了测试,但是在vb.net中,它向我显示了847.999999。
这是计算表
Private Function Calcuatedemeter(ByVal cartonnumber As Integer, ByVal platenumber As Integer) As String
Dim result As String = ""
Dim sb As New System.Text.StringBuilder()
If cartonnumber > 0 Then
sb.Append(cartonnumber)
sb.Append(" Carton ")
End If
If Not platenumber = 0 And cartonnumber > 0 Then
sb.Append(" و ")
End If
If platenumber > 0 Then
sb.Append(" " & platenumber & " Peace ")
End If
result = sb.ToString
Return result
End Function
并使用此功能iam混入数据库中的值
Function getInfoceramic(ByVal gsize As Double, ByVal gcarton As Integer, ByVal gname As String, ByVal gwidth As Double, ByVal glength As Double) As Double
size = CDbl(gsize)
cartonpak = gcarton
name = gname
width = gwidth
length = glength
platesize = (width / 100) * (length / 100)
End Function
答案 0 :(得分:0)
这是由于双精度值的性质所致,它们不存储为精确值,而是存储为非精确近似值。
这很容易理解,并且与错误有关(请参见:https://en.wikipedia.org/wiki/Machine_epsilon)
要解决此问题,如果您知道只处理2个小数位,则可以使用整数并将其乘以100进行存储,然后在要输出该值时仅除以100。