Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 working with numbers
tempo Offline
Junior Member
**
Posts: 30
Joined: Aug 2012
Post: #1
working with numbers
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!
01-03-2015 07:03 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: working with numbers
If you have the start and end price, why would you need to store the discount (as opposed to calculating it when displaying)?

My Blog
01-03-2015 06:16 PM
Find all posts by this user Quote this message in a reply
tempo Offline
Junior Member
**
Posts: 30
Joined: Aug 2012
Post: #3
RE: working with numbers
i want to calculate the discount and display it..... (no need to store the value)
01-04-2015 05:49 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: working with numbers
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.


My Blog
01-05-2015 09:32 AM
Find all posts by this user Quote this message in a reply
tempo Offline
Junior Member
**
Posts: 30
Joined: Aug 2012
Post: #5
RE: working with 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!!!)
(This post was last modified: 01-05-2015 11:00 PM by tempo.)
01-05-2015 03:54 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #6
RE: working with numbers
Please read up on <setvar>.

(01-05-2015 03:54 PM)tempo Wrote:  (please answer Yes!!!)
No.

My Blog
01-09-2015 10:40 PM
Find all posts by this user Quote this message in a reply
tempo Offline
Junior Member
**
Posts: 30
Joined: Aug 2012
Post: #7
RE: working with numbers
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)
01-31-2015 11:34 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #8
RE: working with numbers
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.

My Blog
02-01-2015 12:18 PM
Find all posts by this user Quote this message in a reply
tempo Offline
Junior Member
**
Posts: 30
Joined: Aug 2012
Post: #9
RE: working with numbers
(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.....
02-01-2015 03:49 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #10
RE: working with numbers
Please re-read how to place PHP expressions in templates.

My Blog
02-01-2015 10:41 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: