calculating in the command line interface

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

calculating in the command line interface

jose isaias cabrera

So, I needed to get a really low percentage and I went to the SQlite3 command prompt and I typed,

select  round(133/122000,10) as t;

that gave me 0.0.  Then, I said, ok, let's try this,

select round(1/2,10) as t;

that also gave me 0.0.  Then I said, hmmmm, let me try this,

select round(10/2,10) and that gave me 5.0, which is what I expect.  Is there a way that I can calculate some fractional numbers in the sqlite3 command line?  I am using v3.8.6.  Thanks.

josé
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: calculating in the command line interface

Stephan Beal-3
On Wed, Oct 1, 2014 at 4:27 PM, jose isaias cabrera <[hidden email]
> wrote:

>
> So, I needed to get a really low percentage and I went to the SQlite3
> command prompt and I typed,
>
> select  round(133/122000,10) as t;
>
> that gave me 0.0.  Then, I said, ok, let's try this,
>
> select round(1/2,10) as t;
>
> that also gave me 0.0.  Then I said, hmmmm, let me try this,
>

You're doing integer math. You need floating point:

select round(1/2,10) as t;
0.5


--
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
"Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do." -- Bigby Wolf
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: calculating in the command line interface

Igor Tandetnik-2
On 10/1/2014 10:34 AM, Stephan Beal wrote:
> You're doing integer math. You need floating point:
>
> select round(1/2,10) as t;

You probably meant  round(1.0/2, 10), or   round(1/2.0, 10)  or similar.
--
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: calculating in the command line interface

John Hascall-2
In reply to this post by jose isaias cabrera
​You got bit by integer division...

asw-1# {773} *sqlite3*
SQLite version 3.7.5
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> *select round(133.0/122000.0,10) as t;*
0.0010901639
sqlite>


BTW, there are other tools for simple math...​

asw-1# {772} *bc -l*

*scale=10133/122000*
.0010901639


On Wed, Oct 1, 2014 at 9:27 AM, jose isaias cabrera <[hidden email]
> wrote:

>
> So, I needed to get a really low percentage and I went to the SQlite3
> command prompt and I typed,
>
> select  round(133/122000,10) as t;
>
> that gave me 0.0.  Then, I said, ok, let's try this,
>
> select round(1/2,10) as t;
>
> that also gave me 0.0.  Then I said, hmmmm, let me try this,
>
> select round(10/2,10) and that gave me 5.0, which is what I expect.  Is
> there a way that I can calculate some fractional numbers in the sqlite3
> command line?  I am using v3.8.6.  Thanks.
>
> josé
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: calculating in the command line interface

Stephan Beal-3
In reply to this post by Stephan Beal-3
On Wed, Oct 1, 2014 at 4:34 PM, Stephan Beal <[hidden email]> wrote:

> You're doing integer math. You need floating point:
>
> select round(1/2,10) as t;
> 0.5
>

And this time with the right copy/paste buffer:

sqlite> select round(1.0/2,10) as t;
0.5


--
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
"Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do." -- Bigby Wolf
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: calculating in the command line interface

jose isaias cabrera
In reply to this post by Igor Tandetnik-2

"Igor Tandetnik" wrote...

> On 10/1/2014 10:34 AM, Stephan Beal wrote:
>> You're doing integer math. You need floating point:
>>
>> select round(1/2,10) as t;
>
> You probably meant  round(1.0/2, 10), or   round(1/2.0, 10)  or similar.

Thanks, Igor.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: calculating in the command line interface

jose isaias cabrera
In reply to this post by Stephan Beal-3

"Stephan Beal" wrote...

> On Wed, Oct 1, 2014 at 4:34 PM, Stephan Beal <[hidden email]>
> wrote:
>
>> You're doing integer math. You need floating point:
>>
>> select round(1/2,10) as t;
>> 0.5
>>
>
> And this time with the right copy/paste buffer:
>
> sqlite> select round(1.0/2,10) as t;
> 0.5
I was going to reply to your original email and ask what version were you
using.;-)  Yes, this one works.  And thank you all that responded.

_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users