dbTalk Databases Forums  

round up

comp.databases.mysql comp.databases.mysql


Discuss round up in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
christian
 
Posts: n/a

Default round up - 05-05-2008 , 06:37 PM






Sorry but I'm very newbie for writing my own script
I try
$result = mysql_query("SELECT
cardnum,callednum,disposition,billseconds,truncate (billcost /10000,2)
,callstart FROM cdrs WHERE disposition='ANSWER' and cardnum='$poste' ORDER
BY callstart DESC ");
or
$result = mysql_query("SELECT
cardnum,callednum,disposition,billseconds,round(bi llcost /10000,2)
,callstart FROM cdrs WHERE disposition='ANSWER' and cardnum='$poste' ORDER
BY callstart DESC ");

I whant up rounded billcost by step of 0,05
ex 0,01 is 0,05 or 0,06 is 0,1 and 0,11 is 0,15
Any idea ?
Thanks



Reply With Quote
  #2  
Old   
cvh@LE
 
Posts: n/a

Default Re: round up - 05-06-2008 , 02:45 AM






On 6 Mai, 01:37, "christian" <christ... (AT) comdif-nospam (DOT) com> wrote:
Quote:
Sorry but I'm very newbie for writing my own script
I try
$result = mysql_query("SELECT
cardnum,callednum,disposition,billseconds,truncate (billcost /10000,2)
,callstart FROM cdrs WHERE disposition='ANSWER' and cardnum='$poste' ORDER
BY callstart DESC ");
or
$result = mysql_query("SELECT
cardnum,callednum,disposition,billseconds,round(bi llcost /10000,2)
,callstart FROM cdrs WHERE disposition='ANSWER' and cardnum='$poste' ORDER
BY callstart DESC ");

I whant up rounded billcost *by step of 0,05
ex 0,01 is 0,05 or 0,06 is 0,1 and 0,11 is 0,15
Any idea ?
Thanks
All you need is a bit of math

mysql> set @number=0.01;
Query OK, 0 rows affected (0.00 sec)

mysql> select ceiling(@number*20)/20;
+------------------------+
Quote:
ceiling(@number*20)/20 |
+------------------------+
0.0500 |
+------------------------+
1 row in set (0.00 sec)

mysql> set @number=0.06;
Query OK, 0 rows affected (0.00 sec)

mysql> select ceiling(@number*20)/20;
+------------------------+
Quote:
ceiling(@number*20)/20 |
+------------------------+
0.1000 |
+------------------------+
1 row in set (0.00 sec)

mysql>

mysql> set @number=0.11;
Query OK, 0 rows affected (0.00 sec)

mysql> select ceiling(@number*20)/20;
+------------------------+
Quote:
ceiling(@number*20)/20 |
+------------------------+
0.1500 |
+------------------------+
1 row in set (0.00 sec)

mysql> set @number=0.15;
Query OK, 0 rows affected (0.00 sec)

mysql> select ceiling(@number*20)/20;
+------------------------+
Quote:
ceiling(@number*20)/20 |
+------------------------+
0.1500 |
+------------------------+
1 row in set (0.00 sec)

mysql>


Reply With Quote
  #3  
Old   
christian
 
Posts: n/a

Default Re: round up - 05-06-2008 , 04:02 AM



Thanks for you answer it work great !!

I have changed
$result = mysql_query("SELECT
cardnum,callednum,disposition,billseconds,ceiling( (truncate((billcost +
1000)/10000,2))*20)/20,callstart,datecall FROM cdrs WHERE
disposition='ANSWER' and cardnum='$poste' ORDER BY callstart DESC ");

I have (billcost + 1000) because 1000 is the connection price



"cvh@LE" <christian.hansel (AT) cpi-service (DOT) com> a écrit dans le message de news:
80583eaa-169c-49e2-a75f-a598ea84ead3...oglegroups.com...
On 6 Mai, 01:37, "christian" <christ... (AT) comdif-nospam (DOT) com> wrote:
Quote:
Sorry but I'm very newbie for writing my own script
I try
$result = mysql_query("SELECT
cardnum,callednum,disposition,billseconds,truncate (billcost /10000,2)
,callstart FROM cdrs WHERE disposition='ANSWER' and cardnum='$poste' ORDER
BY callstart DESC ");
or
$result = mysql_query("SELECT
cardnum,callednum,disposition,billseconds,round(bi llcost /10000,2)
,callstart FROM cdrs WHERE disposition='ANSWER' and cardnum='$poste' ORDER
BY callstart DESC ");

I whant up rounded billcost by step of 0,05
ex 0,01 is 0,05 or 0,06 is 0,1 and 0,11 is 0,15
Any idea ?
Thanks
All you need is a bit of math

mysql> set @number=0.01;
Query OK, 0 rows affected (0.00 sec)

mysql> select ceiling(@number*20)/20;
+------------------------+
Quote:
ceiling(@number*20)/20 |
+------------------------+
0.0500 |
+------------------------+
1 row in set (0.00 sec)

mysql> set @number=0.06;
Query OK, 0 rows affected (0.00 sec)

mysql> select ceiling(@number*20)/20;
+------------------------+
Quote:
ceiling(@number*20)/20 |
+------------------------+
0.1000 |
+------------------------+
1 row in set (0.00 sec)

mysql>

mysql> set @number=0.11;
Query OK, 0 rows affected (0.00 sec)

mysql> select ceiling(@number*20)/20;
+------------------------+
Quote:
ceiling(@number*20)/20 |
+------------------------+
0.1500 |
+------------------------+
1 row in set (0.00 sec)

mysql> set @number=0.15;
Query OK, 0 rows affected (0.00 sec)

mysql> select ceiling(@number*20)/20;
+------------------------+
Quote:
ceiling(@number*20)/20 |
+------------------------+
0.1500 |
+------------------------+
1 row in set (0.00 sec)

mysql>




Reply With Quote
  #4  
Old   
Captain Paralytic
 
Posts: n/a

Default Re: round up - 05-06-2008 , 04:57 AM



On 6 May, 10:02, "christian" <christ... (AT) comdif-nospam (DOT) com> wrote:
Quote:
Thanks for you answer it work great !!

I have changed
$result = mysql_query("SELECT
cardnum,callednum,disposition,billseconds,ceiling( (truncate((billcost +
1000)/10000,2))*20)/20,callstart,datecall FROM cdrs WHERE
disposition='ANSWER' and cardnum='$poste' ORDER BY callstart DESC ");

I have (billcost + 1000) because 1000 is the connection price

"cvh@LE" <christian.han... (AT) cpi-service (DOT) com> a écrit dans le message de news:
80583eaa-169c-49e2-a75f-a598ea84e... (AT) 26g2000hsk (DOT) googlegroups.com...
On 6 Mai, 01:37, "christian" <christ... (AT) comdif-nospam (DOT) com> wrote:



Sorry but I'm very newbie for writing my own script
I try
$result = mysql_query("SELECT
cardnum,callednum,disposition,billseconds,truncate (billcost /10000,2)
,callstart FROM cdrs WHERE disposition='ANSWER' and cardnum='$poste'ORDER
BY callstart DESC ");
or
$result = mysql_query("SELECT
cardnum,callednum,disposition,billseconds,round(bi llcost /10000,2)
,callstart FROM cdrs WHERE disposition='ANSWER' and cardnum='$poste'ORDER
BY callstart DESC ");

I whant up rounded billcost by step of 0,05
ex 0,01 is 0,05 or 0,06 is 0,1 and 0,11 is 0,15
Any idea ?
Thanks

All you need is a bit of math

mysql> set @number=0.01;
Query OK, 0 rows affected (0.00 sec)

mysql> select ceiling(@number*20)/20;
+------------------------+
| ceiling(@number*20)/20 |
+------------------------+
| 0.0500 |
+------------------------+
1 row in set (0.00 sec)

mysql> set @number=0.06;
Query OK, 0 rows affected (0.00 sec)

mysql> select ceiling(@number*20)/20;
+------------------------+
| ceiling(@number*20)/20 |
+------------------------+
| 0.1000 |
+------------------------+
1 row in set (0.00 sec)

mysql

mysql> set @number=0.11;
Query OK, 0 rows affected (0.00 sec)

mysql> select ceiling(@number*20)/20;
+------------------------+
| ceiling(@number*20)/20 |
+------------------------+
| 0.1500 |
+------------------------+
1 row in set (0.00 sec)

mysql> set @number=0.15;
Query OK, 0 rows affected (0.00 sec)

mysql> select ceiling(@number*20)/20;
+------------------------+
| ceiling(@number*20)/20 |
+------------------------+
| 0.1500 |
+------------------------+
1 row in set (0.00 sec)

mysql
You are welcome to your answer Christian, but please do not top post.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.