Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 16079

why fix( a * b ) may be error but fix( cdbl(a * b) ) is the right ?

$
0
0
hi all ~

Option Explicit

Private Sub Form_Load()
Dim a1_dbl As Double
Dim a2_dbl As Double
Dim a3_dbl As Double

Dim c1_sng As Single
Dim c2_sng As Single
Dim c3_sng As Single
'
'a1_dbl = 1.9 * 10#
'c1_sng = 1.9! * 10!
'Debug.Print Fix(c1_sng), Fix(a1_dbl), Fix(1.9 * 10)
'
'c1_sng = 1.9
'c2_sng = 10
'c3_sng = c1_sng * c2_sng
'Debug.Print Fix(c3_sng), Fix(c1_sng * c2_sng)


a1_dbl = 1.9
a2_dbl = 10
c1_sng = a1_dbl * a2_dbl
a3_dbl = a1_dbl * a2_dbl
Debug.Print Fix(a1_dbl * a2_dbl) '---> it show 18
Debug.Print Fix(c1_sng), Fix(a3_dbl) '---> it show 19
Debug.Print Fix(CDbl(a1_dbl * a2_dbl)), Fix(CSng(a1_dbl * a2_dbl)) '---> it show 19
Debug.Print Fix(CDbl(a1_dbl) * CDbl(a2_dbl)), Fix(CSng(a1_dbl) * CSng(a2_dbl)) '---> it show 18

Debug.Print 19- (1.9*10) '---> it show not zero
Debug.Print 19-cdbl(1.9*10) '---> it show zero
Debug.Print 19-csng(1.9*10) '---> it show zero
Debug.Print 19-cdbl(1.9)*cdbl(10) '---> it show not zero
Debug.Print 19-cstr(1.9)*cstr(10) '---> it show not zero


QQQ 1.9 * 10 '---> it show zero
QQQ CDbl(1.9 * 10) '---> it show zero

End

End Sub

Sub QQQ(v)

Debug.Print 19 - v


End Sub

Viewing all articles
Browse latest Browse all 16079

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>