The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
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? |
#2
|
||||
|
||||
Quote:
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); |
#3
|
||||
|
||||
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 |
#4
|
||||
|
||||
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 |
#5
|
||||
|
||||
Create a plugin at the hook postbit_display_complete. Add this PHP code:
PHP Code:
|
#6
|
||||
|
||||
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. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|