Int.htm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>Int( value )</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. value = a number, or a string which represents a number
  13. </td>
  14. </tr>
  15. </table>
  16. <h1>Description</h1>
  17. <table>
  18. <tr>
  19. <td>
  20. Converts the value to the nearest integer. <br />
  21. <br />
  22. This is the same as Blitz's automatic type conversion. <br />
  23. So the two commands... <br />
  24. <br />
  25. n = value <br />
  26. n = Int( value ) <br />
  27. <br />
  28. ... do exactly the same thing when n is an integer variable. <br />
  29. <br />
  30. If Int is applied to a string it converts as much as possible: <br />
  31. <br />
  32. Int( "10" ) ........ result is 10 <br />
  33. Int( "3.7" ) ....... result is 3, stops at "." which can't be part of an integer <br />
  34. Int( "junk3" ) .... result is 0, stops at "j" <br />
  35. <br />
  36. Int converts floating point numbers by rounding to the nearest integer. <br />
  37. NOTE: This is not the traditional meaning of Int in Basic. <br />
  38. <br />
  39. What about numbers exactly halfway between integers? <br />
  40. The rounding is to the nearest even integer: <br />
  41. <br />
  42. Int( 2.5 ) ... produces 2 <br />
  43. Int( 3.5 ) ... produces 4 <br />
  44. <br />
  45. See also Floor and Ceil for other types of rounding.
  46. </td>
  47. </tr>
  48. </table>
  49. <h1><a href=../2d_examples/Int.bb>Example</a></h1>
  50. <table>
  51. <tr>
  52. <td>
  53. ; Ceil / Floor / Int example, three kinds of rounding. <br />
  54. <br />
  55. ; Move mouse. Escape quits. <br />
  56. <br />
  57. Graphics 640, 480 <br />
  58. <br />
  59. Const KEY_ESC = 1 <br />
  60. <br />
  61. SetBuffer BackBuffer() <br />
  62. Origin 320, 240 <br />
  63. <br />
  64. MoveMouse 320, 240 : HidePointer <br />
  65. <br />
  66. While Not KeyDown( KEY_ESC ) <br />
  67. <br />
  68. Cls <br />
  69. <br />
  70. my = MouseY() - 240 <br />
  71. Color 100, 100, 0 <br />
  72. Line -320, my, 319, my <br />
  73. <br />
  74. DrawNumberLine <br />
  75. <br />
  76. y# = Float( -my ) / 32 <br />
  77. <br />
  78. Text 100, 50, " y = " + y <br />
  79. Text 100, 70, " Ceil( y ) = " + Ceil( y ) <br />
  80. Text 100, 90, " Floor( y ) = " + Floor( y ) <br />
  81. Text 100, 110, " Int( y ) = " + Int( y ) <br />
  82. <br />
  83. Flip <br />
  84. <br />
  85. Wend <br />
  86. End <br />
  87. <br />
  88. Function DrawNumberLine( ) ; vertical line with numeric labels <br />
  89. <br />
  90. Color 255, 255, 255 <br />
  91. Line 0, -240, 0, 239 <br />
  92. <br />
  93. For n = -7 To 7 <br />
  94. yn = -32 * n <br />
  95. Line -2, yn, 2, yn <br />
  96. Text -30, yn - 6, RSet( n, 2 ) <br />
  97. Next <br />
  98. <br />
  99. End Function
  100. </td>
  101. </tr>
  102. </table>
  103. <br>
  104. <a target=_top href=../index.htm>Index</a><br>
  105. <br>
  106. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=Int&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  107. </html>