vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   percentage code is way off on large boards (https://vborg.vbsupport.ru/showthread.php?t=63062)

Boofo 03-28-2004 01:31 PM

percentage code is way off on large boards
 
Can anyone plaese tell me what I am doing wrong in the following code that would cause larger boards with high post and thread counts to display these percentages really far off?

PHP Code:

$statscache['activepercent'] = vb_number_format(($numbermembers $newuserid) * 1002) . '%';

$statscache['topthreadspercent'] = vb_number_format(($topstarter['count'] / $getthreadviews['count']) * 1002) . '%'

On my smaller board they are very accurate. But on a larger board they seem to be showing up like the following:

15,300 Posts (15,300.00%)

I have tried different variations of this and they all turn out the same.

assassingod 03-28-2004 01:42 PM

Don't know if this'll work or not, but try dividing by a hundred (or 10 or 1000):
PHP Code:

if($stats['activepercent'] > 100)
{
$statscache['activepercent'] = vb_number_format(($numbermembers $newuserid) * 100 1000) . '%'
}
else
{
 
$statscache['activepercent'] = vb_number_format(($numbermembers $newuserid) * 1002) . '%';



Boofo 03-28-2004 01:46 PM

Thanks. Steve. I'll have someone with a large board test this and get back to you here with the results. ;)

Boofo 03-28-2004 01:57 PM

Steve, do you know how to take the last 2 zeros after the decimal point off on a whole percent? Like if it is 50.00%, how would you make it so it showed up as 50%, but ONLY on whole percentages? If it is like 50.05%, I want that to show up.

AN-net 03-28-2004 05:24 PM

you could round it;)

Boofo 03-28-2004 05:56 PM

But that wouldn't leave it if it was 50.05%, would it? ;)

AN-net 03-28-2004 06:11 PM

you could creat some kind if statement:)

Boofo 03-28-2004 06:26 PM

Any examples? ;)

John 03-28-2004 10:11 PM

Quote:

Originally Posted by Boofo
Any examples? ;)

PHP Code:

// If you've got a percentage value like this:
$percentage 50.05;

// You can lob off the last two digits:
$lasttwo substr($percentage, -2);

// And then see if that equals 00
if ($lasttwo == '00')
{
     
// intval returns an integer value
     
$percentage intval($percentage);
}

// echo it out, you'll see that if $lasttwo == 00, it returns an int
echo $percentage

There's probably an infinitely more simple method of doing it, lol - but it works. :)

Boofo 03-29-2004 12:13 AM

As long as it works, that's all that really counts. Thank you, sir. ;)

Would you have any ideas on the percentage problems for bigger boards? )

EDIT: How would I incorporate this with this code?

PHP Code:

if($stats['activepercent'] > 100

$statscache['activepercent'] = vb_number_format(($numbermembers $newuserid) * 100 1000) . '%'

else 

$statscache['activepercent'] = vb_number_format(($numbermembers $newuserid) * 1002) . '%'




All times are GMT. The time now is 06:05 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01105 seconds
  • Memory Usage 1,746KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete