MyBB Hacks

Full Version: working with numbers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi, i'm working with XThreads, a really great plugin.

i want to know the way to work with numbers.....

for example,

there is two custom fields

custom_field_1: start_price
custom_field_2: end_price

is it possible to calculate and store into a custom field the discount using the custom_field_1 and custom_field_2

thanks for the support!
If you have the start and end price, why would you need to store the discount (as opposed to calculating it when displaying)?
i want to calculate the discount and display it..... (no need to store the value)
If you use Template Conditionals:

Code:
<?=(float)$threadfields['end_price'] - (float)$threadfields['start_price']?>


Note that I'm assuming that the prices are really numbers.

it works!!!


Can i store this discount to a custom variable?

by the way....one more question,

i have a custom field "Price". This field used by 2 forums (or subforums), for example "radio" and "tv". Is it possible to calculate the average value of the field "Price" based on the values of any forum? When a user  select the forum "radio" before the list of the thread i want to display the average value based on the field "Price" of this forum threads.
Is it possible? (please answer Yes!!!)
Please read up on <setvar>.

(01-05-2015 03:54 PM)tempo Wrote: [ -> ](please answer Yes!!!)
No.
i'm using 2 custom fields X and Y to calculate and display the Z value like this:

<setvar Z>(float)$threadfields['X']*100/(float)$threadfields['Y'] </setvar>
<td>{$tplvars['Z']}</td>

the problem is that the value of Z is 10.33333 (for example).

Can i rounding this Z value? (to show 10.5 for example)
http://php.net/manual/en/function.round.php

Rounding generally rounds to decimal places, so 10.5 is an odd rounding.  It's probably doable, but depends on exactly what precision you're looking for.
(02-01-2015 12:18 PM)ZiNgA BuRgA Wrote: [ -> ]http://php.net/manual/en/function.round.php

Rounding generally rounds to decimal places, so 10.5 is an odd rounding.  It's probably doable, but depends on exactly what precision you're looking for.

thanks for the link but my problem is: i can't find the correct syntax into the template about the variable Z (check my example above)

for example i'm using: round($tplvars['Z'],1) and nothing happens.....
Please re-read how to place PHP expressions in templates.
Pages: 1 2
Reference URL's