Repository navigation
Cint
Home › Converting Data Types › CInt
Converts a number or string to an Integer, rounding to the nearest; no overflow check.
Declare Function CInt ( ByVal expression As datatype ) As Integer
Declare Function CInt<bits> ( ByVal expression As datatype ) As Integer<bits>
Type typename
Declare Operator Cast ( ) As Integer
Declare Operator Cast ( ) As Integer<bits>
End Typebitsexpressiondatatypetypename
If CInt is passed a numeric expression, it rounds it using using the round-to-even method - i.e. it rounds to the closest integer value, choosing the closest even integer if the number is equidistant from two integers - and returns an Integer, or if a bits value is supplied, an integer type of the given size.
The function does not check for an overflow; for example, for a 32-bit Integer the results are undefined for values which are less than -2 147 483 648 or larger than 2 147 483 647.
If the argument is a string expression, it is converted to numeric by using ValInt or ValLng, depending on the size of the result type.
The name "CINT" is derived from 'Convert to INTeger'.
An Integer or Integer<bits> containing the converted value.
result = CInt( expression )
result = CInt( string expression )
result = CInt( user defined type )- In the -lang qb dialect,
CIntwill return a 16-bit integer, like in QB.
- The string argument was not allowed in QB
- The
<bits>parameter was not allowed in QB
' Using the CINT function to convert a numeric value
'Create an INTEGER variable
Dim numeric_value As Integer
'Convert a numeric value
numeric_value = CInt(300.5)
'Print the result, should return 300, because 300 is even
numeric_value = CInt(301.5)
'Print the result, should return 302, because 301 is odd
Print numeric_valueCategory: Converting Data Types
Kind: function
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing