vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Rounding? (https://vborg.vbsupport.ru/showthread.php?t=43562)

[D]Vincent 09-15-2002 07:00 AM

Rounding?
 
How would you get a number to round if it went into a decimal, like let's say I have 100.2, how would i get that to automatically go to 100? Or is there not a way?

Admin 09-15-2002 02:52 PM

PHP's round() function, or sprintf() for older versions.

[D]Vincent 09-15-2002 03:38 PM

Thanks ^^

But umm.. with the round how would I use it? Like how would I get it to know that it goes a decimal over to round up to the nearest 1?

futureal 09-15-2002 05:37 PM

You can use something like this:

PHP Code:

// round number up
$roundedup ceil($number);

// round number down
$roundeddown floor($number);

// round to nearest
$roundednearest round($number); 


[D]Vincent 09-15-2002 08:40 PM

Vincent]So if I did
PHP Code:

$blah1 $blah2 "1.2"

And $blah1 ended up being let's say 366.6 and I did
PHP Code:

 $blah round($blah1); 

then it would round it to 367 correct?

futureal 09-16-2002 09:19 PM

Correct. The round() function will always go to the nearest integer, while ceil() and floor() round up and down, respectively.

[D]Vincent 09-23-2002 10:16 AM

What if blah1 ended up being 205 and didn't have a decimal? Then what would happen?

Admin 09-23-2002 02:28 PM

If the number you are rounding is already an integer, it will stay the same. :)


All times are GMT. The time now is 11:10 PM.

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.01813 seconds
  • Memory Usage 1,721KB
  • 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
  • (3)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete