Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

Simple PHP code to drop the .00 if the price is over 100.00


Recommended Posts

so lets say you have this string $sp_price - SHOWN IN SPECIALS.


This doesnt always fit so i would like it to display 100€ instead of 100.00€


for lower priced items 56.99...etc will show as normal,


I only want to drop the .00 when there are 3 leading numbers before the .(dot)





Please help!



Link to comment
Share on other sites

I would check if the price is higher than 100 and if yes round it using round() or floor() whatever fits your thought better


$sp_price = $sp_price > 100 ? floor($sp_price) : $sp_price ;


I would suggest to read the php manuals for exact results of that functions

Link to comment
Share on other sites




$data = '<div class="infoBoxWrapper box2">' . tep_draw_box_wrapper_top() .

' <div class="infoBoxHeading">' . tep_draw_box_title_top() . '<a href="' . tep_href_link(FILENAME_SPECIALS) . '">' . MODULE_BOXES_SPECIALS_BOX_TITLE . '</a>' . tep_draw_box_title_bottom() . '</div>' .

' <div class="infoBoxContents">' . tep_draw_box_content_top() .


' <div class="pic_padd wrapper_pic_div" align="center" style="width:'.(BOX_IMAGE_WIDTH).'px;height:'.(BOX_IMAGE_HEIGHT).'px;">'.$pic_prod.'</a></div>'. "\n".

' <div class="box-padd">'. "\n".

' <div class="name name_padd">'.$name_prod.'</div>'. "\n".

// ' <div class="desc desc_padd">'.$p_desc.'</div>'. "\n".

' <div class="price_padd"><b>'.PRICE. '</b>'.$sp_price.'</div>'. "\n".

' <div class="button__padd">'.$p_buy_now_text.' '.$p_details_text.'</div>'. "\n".

' </div>'. "\n".

'' . tep_draw_box_content_bottom() . '</div>'. "\n".

'' . tep_draw_box_wrapper_bottom() . '</div>';


$oscTemplate->addBlock($data, $this->group);






I need to code it into this. Any thoughts.

Link to comment
Share on other sites

This only applies to prices over 100, and are integer (0 cents)? Say it's $sp_price you have as "100.00€", and you want it "100€":


Assuming you already have the string fully formatted with the two decimal places and the currency symbol, perhaps you should look at something like

if ($unformatted_price >= 100 && int($unformatted_price) == $unformatted_price) {
$place = strpos($sp_price, ".00");
if ($place > 0) {
	$sp_price = substr($sp_price, 0, $place) . substr($sp_price, $place+3);

That's just one of probably many ways to do this. Note that this code would have to be modified for different currency formatting conventions (decimal point used, number of decimal places, perhaps whether there's any text after the .00, etc.).


If your original $sp_price is just a 100 number (I don't have the code in front of me), you would just format it differently (to 0 decimal places instead of 2) if >= 100. You would have to check the price and format with the standard number of decimal places if <100, and 0 decimal places otherwise.

Link to comment
Share on other sites

Well, that's one point, nobody know what exactly $sp_price is, formatted or not, with or without taxes etc


Other point is what you want to achieve exactly


Lets say you have 2 prices

1) 150.99

2) 150.10


How should the display be?

1) 150

2) 150



1) 151

2) 150

Link to comment
Share on other sites

Agreed. The original request was to drop ".00" so that prices fit the alloted space. If there are a non-zero number of cents (.01 through .99), that's a whole 'nuther issue. Perhaps a better approach would be to increase the space available for price display, so that "150.99€" has the space to be displayed. Then you can worry about displaying "100.00€" or "100€" as a separate issue. I would avoid rounding or truncating a displayed price to an integer, if the customer is actually going to be charged the unmodified price (actually, that would probably be illegal anyway).

Link to comment
Share on other sites

think you're right about being illegal, decimals (cents) must be displayed to every euro price, don't know about usd


An option would be to display like this 150.49 in supermarket style


In any case the price displayed should be the price charged

Link to comment
Share on other sites

When I said "illegal", I was thinking in terms of displaying a lower price than what the customer is actually billed for (e.g., display "150€", charge "150.99€"). I don't think it's illegal, at least in the U.S., to drop .00 (laws would vary by state) but it's uncommon for "small ticket" items, as it might confuse people. Certainly for big-ticket items like a car, they usually don't bother with cents.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...