/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] round ()

if i have a sql statement like so:

[CODE]
SELECT quantity,duration_minutes,
duration_seconds,
quantity /
SUM(duration_minutes + duration_seconds) as total
From process_data
GROUP BY quantity,duration_minutes,
duration_seconds
[/CODE]

The output comes back as 1.6, how do i just round to two using the math round function?

Thanks in advance.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 05.2012 — [code=php]
echo round($value);
[/code]
...should be sufficient
Copy linkTweet thisAlerts:
@SupplementauthorNov 05.2012 — Thanks NogDog,

That worked well, although it's outputting to the nearest decimal but i need it to output to the nearest whole number. I created a new variable $total...

Here's what i got:

[code=php]

<?php

$total = sql::query("SELECT

quantity,duration_minutes,
duration_seconds,
quantity /
SUM(duration_minutes + duration_seconds) as total
From process_data
GROUP BY quantity,duration_minutes,
duration_seconds")
?>


<?php echo ROUND($total); ?>

[/code]



total is 1.688

I would like the result to be "2"

but rather it's giving me "17"

More help would be greatly appreciated.
Copy linkTweet thisAlerts:
@SupplementauthorNov 05.2012 — I thought the syntax was something like:

ROUND ('$total',00.00) right after the SELECT?
Copy linkTweet thisAlerts:
@NogDogNov 05.2012 — Well, [B]$total[/B] is probably a resource ID at that point, not the value of that column in the result record. You probably need to use the applicable "fetch" method for whichever database extension you're using. If you want the SQL to round it for you, the specifics may depend on which flavor of DBMS you are using -- with MySQL it should be something like:
<i>
</i>ROUND(SUM(duration_minutes + duration_seconds)) as total
Copy linkTweet thisAlerts:
@SupplementauthorNov 05.2012 — I'm stuck.
Copy linkTweet thisAlerts:
@SupplementauthorNov 05.2012 — you're right.

when i:

<?php echo print($total_duration);?>

it returned Resource id #211

=/


<?php

$total_duration = sql::query("SELECT

quantity,duration_minutes,

duration_seconds,

quantity /

SUM(duration_minutes + duration_seconds) as total_duration

From process_data

GROUP BY quantity,duration_minutes,

duration_seconds");

?>

<?php echo print($total_duration);?>
Copy linkTweet thisAlerts:
@SupplementauthorNov 05.2012 — I figured it out.

[code=php]<?php

$results = sql::clean_row("
SELECT
quantity,duration_minutes,
duration_seconds
From event.dbo.process_data");
echo $results['duration_minutes'] . " " . $results['duration_seconds'] . " " . $results['quantity'] . "<br />";
$total_duration =(($results['duration_minutes'] * 60 + $results['duration_seconds'])/60) / $results['quantity'];
//echo round($total_duration, 1.0) . "<br />";




echo ROUND($total_duration);
?>[/code]



Thanks for the help NogDog.
×

Success!

Help @Supplement spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...