How To Remove .00 From Drupal 7 Ubercart 3.x Display Price

Sunday, February 24th, 2013
Last Updated:
Sunday, August 13th, 2017

Disclaimer: Accessing the information on this page means you agree to the Sites Terms of Service

I've recently become interested in reading up on "marketing" tactics, especially for websites. Once you get an online store up and going, it's making money and everybody's fat and happy, the owners always seem to want more. This is where the whole traffic vs conversions comes into play and there are all sorts of different ways to convert a person to do whatever you need them to convert to for a website. Contact form, sign up for a news letter, fill out a survey or in the case of an Ubercart store, buy a product.

I happened to run across an excellent article on HubSpot's Inbound Marketing Blog labeled: 7 Pricing Mistakes That Can Seriously Stifle Sales. While each and every point is very interesting and worth noting, I was especially intrigued by Point #7: Not Keeping Prices Simple. In this section, they mention how people perceive numbers and when a price has a thousands separator (comma) or a decimal, it inflates the value of the number in the mind of the customer. (It's all psychology stuff and they did lots of a/b testing on it...) Point being, if you have the following numbers:


Psychologically, the third number appears like the cheapest number and tends to convert sales more than the fully formatted price. So, I decided to give it a whirl on the ol' Ubercart website to see how it does... only, Ubercart won't let you format the number to get rid of the empty decimal .00 and I had a few products with change like $34.99 so naturally wanted to keep the decimal if there's anything other than an empty .00

You have a few options in Store -> Configuration -> Currency Format like removing the thousands marker (which you will want to do) or you can set the decimal place to 0, but this gets rid of the decimal completely so if you have a number like $5.34, it gets rid of the .34 and that's really not good... I asked for a feature request to have a simple checkbox added to accomplish this on the currency format page but was promptly denied and told to just theme it. (If you want to see this added as a feature, be sure to re-open the issue and make a stink about it)

Now, I personally don't know much about programming, let alone theming anything on Drupal so when I was told to "just theme it", I was rather disappointed. But, I was given some direction by another comment and set out to figure out how to override theme_uc_price(). Doing a Google search for some PHP code on how to accomplish this, I found all sorts of involved ways but ended up running across which gave me a good starting point:

print str_replace(".0","",$output); //Remove trailing .0 from decimals

This ultimately led to:

function theme_uc_price($variables) {
  $output = '<span class="uc-price">' . str_replace(".00","",uc_currency_format($variables['price'])) . '</span>';
  if (!empty($variables['suffixes'])) {
    $output .= '<span class="price-suffixes">' . implode(' ', $variables['suffixes']) . '</span>';
  return $output;

If you aren't much on programming, you add the above code to your theme's template.php file. If it doesn't exist, just create it in the root of your theme. The next step is to rename theme_uc_price with whatever the name of your theme is (you can find the machine name in the theme .info file). So as an example, one of the core themes for Drupal 7 is "Bartik" and it's machine name is "bartik". Simply rename theme_uc_price to bartik_uc_price.

1) This method works fine with Panels
2) This method does NOT work with views. You have to change the Display Price fields "Format" from Ubercart Price to Numeric and set the thousands marker to -none-

I'm guessing there aren't a lot of people out there who need to do this, or even think about the marketing aspects of a shopping cart but if you're the type who knows the importance, hopefully this post will save you some time.

Got some feedback? Let me know in the comments!

Post Comment


Hey, this method DOES work with views, at least on current versions. You just need to choose the views field formatter type "Ubercart price" (default) instead of "Number", or whichever it's called.

I've tried this and odd enough it ONLY affects the price in Views, not in my node template.

I think I read that Views was eventually updated to pass the price through another function, which makes sense that this works in Views.

What doesn't make sense to me is why it doesn't work in my node template.

I'm printing my price like so: print uc_currency_format($node->sell_price);

Are you printing the price some other way?