Hi,
Over in #217359: Question: integer vs decimal?, you mention that instead of using decimals to represent userpoints, another option is to use integers (a penny a point) and display them divided by 10... so 550 points = $5.50 . Is there a single place where I can put the $points/10 code so that points will always display that way? Or do I need to write it out explicitly each time I call userpoints_get_current_points() for display?

Thanks!
Eileen

Comments

kbahey’s picture

Title: Easiest way to display userpoints as dollars/cents? » Have a centralized theme function for points display
Version: 5.x-3.5 » 5.x-3.x-dev
Category: support » feature

The points have always been an integer (no fractional points) and hence this use case have never been considered as a common one.

So, I am changing this to a feature request for making it a theme function, and then everyone can display them the way they want.

Patches welcome for this ...

jredding’s picture

unfortunately there is no single way of doing it..
for /userpoints you can use function theme_userpoints_list_users_row(&$row) {

kbahey’s picture

What I meant was :

function theme_format_userpoints($points) {
  return $points;
}

Then this can be overridden in template.php by anything. In Eileen's case, assuming points represents cents, it would be:

function phptemplate_format_userpoints($points) {
  return number_format((float)$points/100, 2);
}

As I said, patches to make this happen are welcome.

jredding’s picture

Version: 5.x-3.x-dev » master

moving this to head as I missed it in the latest run of new code.

kmillecam’s picture

We've discussed the use of fractional points in the past.

Our site awards .5 points to users who vote on articles and .1 points
for users who click on an affiliate banner ad.

We had to hack the userpoints module to make this happen by:

1) modifying the database fields (points and max_points) to float instead of integer.
2) removing (int) from queries that pull point balances from the database.
3) changing %d to %f in cases where points where being handled.

HTH,
Kevin

jredding’s picture

well the idea with moving it to a theme function is that you just /10 and then you have your half points.

i.e. where you normally award 1 point, award 10, .5 is 5 points then theme to make it display correctly.

It avoid some of the other issues that were discussed in the past (over on g.d.o).

jredding’s picture

man I should really read the entire issue before commenting. Sorry commenting when you're tired is never a good idea.

kmillecam, ya we've had this discussion before. My bad.

We should probably put this information into the handbook (i.e. why up use whole number and what you can do to switch its use)

mrfelton’s picture

Status: Active » Closed (duplicate)

This is a dupe of #1643692: theme function implemented by michaek which was fixed already.