Jump to content
Sign in to follow this  

SQLite round(x,0) doesn't return an integer

Recommended Posts

Using SQLite, I have a table whose columns are type REAL. I want to round the values to integers, but I keep getting a trailing ".0" at the end of every value. For example:

local $aresult,$irows,$icolumns
$iRval = _SQLite_GetTable2d (-1, "SELECT round(2.52,0) FROM records;", $aResult, $iRows, $iColumns)

returns 3.0. That is the correct result of rounding 2.52 to the nearest integer, but I don't want to display the trailing decimal. How can I make my query omit it?

EDIT: never mind, solved it. Used cast(round(x) as integer).

Edited by sigil

Share this post

Link to post
Share on other sites

According to the SQLLite documentation here http://www.sqlite.org/lang_corefunc.html#round

It would appear if you specify two arguments, a floating-point number is returned. If you only specify one argument, an integer is returned.

Not sure how many operations you're doing, but it may be more efficient to call round() with one argument rather than CASTing every result.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...