vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Simple PHP calculation in postbit (https://vborg.vbsupport.ru/showthread.php?t=152147)

aceofspades 07-13-2007 05:14 PM

Simple PHP calculation in postbit
 
Im trying to do a simple calculation in my postbit. Bascially it square roots a vb value and displays the answer to 1 significant figure.

For example if the value is 6 then the real answer would be 2.449... but it would display it as 2. I know pratically nothing about php, so all i have so far is this (which is probably wrong already):

<?php
echo sqrt($input);
?>

Can anyone help me on where i would go from here? It would be much appreciated.

James

EDIT:

Right im a little bit further on thanks to nick from vbnova. To get it to 0 decimal places ( i dont want to round the numbers up / down) ive got this code:

$number = 1.953434;
$number = str_split($number);

$number = $number[0];

But i really dont know how to put these two codes together. Can anyone help me out?

Eikinskjaldi 07-13-2007 11:55 PM

Quote:

Originally Posted by aceofspades (Post 1290126)
Im trying to do a simple calculation in my postbit. Bascially it square roots a vb value and displays the answer to 1 significant figure.

For example if the value is 6 then the real answer would be 2.449... but it would display it as 2. I know pratically nothing about php, so all i have so far is this (which is probably wrong already):

<?php
echo sqrt($input);
?>

Can anyone help me on where i would go from here? It would be much appreciated.

James

EDIT:

Right im a little bit further on thanks to nick from vbnova. To get it to 0 decimal places ( i dont want to round the numbers up / down) ive got this code:

$number = 1.953434;
$number = str_split($number);

$number = $number[0];

But i really dont know how to put these two codes together. Can anyone help me out?


I think Nick is leading you astray, the above code will not work if the final value is more than 1 digit (e.g. sqrt 100). If you want to round down in all cases use floor.

$number = sqrt($input);
$number = floor($number);

Paul M 07-14-2007 12:25 AM

I don't really follow what you want, can you be more specific

i.e. what should be displayed for these examples ;

0.5
1.234
1.78
12.432
27.876
123.45
4567.89

aceofspades 07-15-2007 10:09 AM

Hi Paul, sorry if i didnt explain myself well. For the examples i would like the following displayed (if we are taking your examples as the result of the square root before they are put to 0 DP):

0.5 ----> 0
1.234 ----> 1
1.78 ----> 1
12.432 ----> 12
27.876 ----> 27
123.45 ----> 123
4567.89 ----> 4567

Dismounted 07-15-2007 11:24 AM

Create a plugin at the hook postbit_display_complete. Add this PHP code:
PHP Code:

$sqrt floor(sqrt($input)); 

Now you can use $sqrt in your postbit(_legacy) template.

King Kovifor 07-15-2007 01:55 PM

Your PHP of:

sqrt($input); should return the float of the number; meaning I cannot see anything wrong with it.

If you read PHP's sqrt() page several members have offered alternatives if you would like to try them.


All times are GMT. The time now is 01:06 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.00928 seconds
  • Memory Usage 1,726KB
  • 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
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)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