Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_Round () issue
#18
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):

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()
Reply


Messages In This Thread
_Round () issue - by dcromley - 05-11-2022, 04:08 AM
RE: _Round () issue - by bplus - 05-11-2022, 05:32 AM
RE: _Round () issue - by aurel - 05-11-2022, 09:08 AM
RE: _Round () issue - by SMcNeill - 05-11-2022, 09:47 AM
RE: _Round () issue - by OldMoses - 05-11-2022, 10:33 AM
RE: _Round () issue - by dcromley - 05-11-2022, 05:17 PM
RE: _Round () issue - by dcromley - 05-13-2022, 12:45 AM
RE: _Round () issue - by bplus - 05-13-2022, 01:08 AM
RE: _Round () issue - by SMcNeill - 05-13-2022, 10:49 AM
RE: _Round () issue - by bplus - 05-13-2022, 01:55 PM
RE: _Round () issue - by TarotRedhand - 05-13-2022, 11:16 AM
RE: _Round () issue - by SMcNeill - 05-13-2022, 12:02 PM
RE: _Round () issue - by TarotRedhand - 05-13-2022, 01:07 PM
RE: _Round () issue - by SMcNeill - 05-13-2022, 01:21 PM
RE: _Round () issue - by SMcNeill - 05-13-2022, 02:09 PM
RE: _Round () issue - by bplus - 05-13-2022, 06:03 PM
RE: _Round () issue - by SMcNeill - 05-13-2022, 06:20 PM
RE: _Round () issue - by dcromley - 05-13-2022, 09:28 PM



Users browsing this thread: 1 Guest(s)