05-13-2022, 09:28 PM
(This post was last modified: 05-17-2022, 09:31 PM by dcromley.
Edit Reason: added toLng - correct k1 to k0
)
I thought Int() was working differently on Wednesday than on Friday, but my thread-starting program was incorrect. ! I deleted that. Gad!
I think this is correct (as I thought on Wednesday) and interesting: FWIW, this clearly shows the up and downs: (trust me):
I never even considered the FIX function.
From the Wiki:
The INT function rounds a numeric value down to the next whole number.
The FIX function rounds a numerical value to the next whole number closest to zero.
The _ROUND function rounds to the closest even .. numerical value.
And I'm quite sure (?) that Javascript says FLOOR() = INT()
I think this is correct (as I thought on Wednesday) and interesting: FWIW, this clearly shows the up and downs: (trust me):
Code: (Select All)
_Title "SCREEN256"
Option _Explicit
DefSng A-Z: DefLng I-N: DefStr S
Screen _NewImage(1024, 768, 256)
Color 0, 15
Cls
Dim Shared f
Dim n, k0, k1, k2, k3, k4
Print " "; Chr$(34); "toLng"; Chr$(34); " is the conversion from a single to a long"
Print
Print " f"; Tab(8); " toLng"; Tab(18); " Int(f)"; Tab(28); " Fix(f)"; Tab(38); "_Round(f)"; Tab(48); "Round##(f,0)"
Print
For n = 19 To -20 Step -1
f = n + .5
k0 = f
k1 = Int(f)
k2 = Fix(f)
k3 = _Round(f)
k4 = Round##(f, 0)
Print f; Tab(10); s(k0); Tab(20); s(k1); Tab(30); s(k2); Tab(40); s(k3); Tab(50); s(k4)
Next n
Function Round## (num As _Float, toDecPlace As _Unsigned _Byte) ' SMcNeill
Round = Int(num * 10 ^ toDecPlace + .5) / 10 ^ toDecPlace
End Function
Function s (n) ' aligns n, adds up '^' or down 'v'
Dim ss
ss = Str$(n): If Len(ss) = 2 Then ss = " " + ss
If n < f Then ss = ss + " v" Else ss = ss + " ^"
s = ss
End Function
I never even considered the FIX function.
From the Wiki:
The INT function rounds a numeric value down to the next whole number.
The FIX function rounds a numerical value to the next whole number closest to zero.
The _ROUND function rounds to the closest even .. numerical value.
And I'm quite sure (?) that Javascript says FLOOR() = INT()