| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <html>
- <head>
- <title>Blitz3D Docs</title>
- <link rel=stylesheet href=../css/commands.css type=text/css>
- </head>
- <body>
- <h1>Int( value )</h1>
- <h1>Parameters</h1>
- <table>
- <tr>
- <td>
- value = a number, or a string which represents a number
- </td>
- </tr>
- </table>
- <h1>Description</h1>
- <table>
- <tr>
- <td>
- Converts the value to the nearest integer.
<br />
-
<br />
- This is the same as Blitz's automatic type conversion.
<br />
- So the two commands...
<br />
-
<br />
- n = value
<br />
- n = Int( value )
<br />
-
<br />
- ... do exactly the same thing when n is an integer variable.
<br />
-
<br />
- If Int is applied to a string it converts as much as possible:
<br />
-
<br />
- Int( "10" ) ........ result is 10
<br />
- Int( "3.7" ) ....... result is 3, stops at "." which can't be part of an integer
<br />
- Int( "junk3" ) .... result is 0, stops at "j"
<br />
-
<br />
- Int converts floating point numbers by rounding to the nearest integer.
<br />
- NOTE: This is not the traditional meaning of Int in Basic.
<br />
-
<br />
- What about numbers exactly halfway between integers?
<br />
- The rounding is to the nearest even integer:
<br />
-
<br />
- Int( 2.5 ) ... produces 2
<br />
- Int( 3.5 ) ... produces 4
<br />
-
<br />
- See also Floor and Ceil for other types of rounding.
- </td>
- </tr>
- </table>
- <h1><a href=../2d_examples/Int.bb>Example</a></h1>
- <table>
- <tr>
- <td>
- ; Ceil / Floor / Int example, three kinds of rounding.
<br />
-
<br />
- ; Move mouse. Escape quits.
<br />
-
<br />
- Graphics 640, 480
<br />
-
<br />
- Const KEY_ESC = 1
<br />
-
<br />
- SetBuffer BackBuffer()
<br />
- Origin 320, 240
<br />
-
<br />
- MoveMouse 320, 240 : HidePointer
<br />
-
<br />
- While Not KeyDown( KEY_ESC )
<br />
-
<br />
- Cls
<br />
-
<br />
- my = MouseY() - 240
<br />
- Color 100, 100, 0
<br />
- Line -320, my, 319, my
<br />
-
<br />
- DrawNumberLine
<br />
-
<br />
- y# = Float( -my ) / 32
<br />
-
<br />
- Text 100, 50, " y = " + y
<br />
- Text 100, 70, " Ceil( y ) = " + Ceil( y )
<br />
- Text 100, 90, " Floor( y ) = " + Floor( y )
<br />
- Text 100, 110, " Int( y ) = " + Int( y )
<br />
-
<br />
- Flip
<br />
-
<br />
- Wend
<br />
- End
<br />
-
<br />
- Function DrawNumberLine( ) ; vertical line with numeric labels
<br />
-
<br />
- Color 255, 255, 255
<br />
- Line 0, -240, 0, 239
<br />
-
<br />
- For n = -7 To 7
<br />
- yn = -32 * n
<br />
- Line -2, yn, 2, yn
<br />
- Text -30, yn - 6, RSet( n, 2 )
<br />
- Next
<br />
-
<br />
- End Function
- </td>
- </tr>
- </table>
- <br>
- <a target=_top href=../index.htm>Index</a><br>
- <br>
- 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>
- </html>
|