function event_espresso_calculate_surcharge( $event_cost = 0.00, $surcharge_amount = 0.00, $surcharge_type = 'pct' ) {
// if >0 and is percent, calculate surcharge amount, if flat rate, will just be formatted, surcharge by default is 0.
$surcharge = ( $surcharge_amount > 0 ) && ( $surcharge_type == 'pct' ) ? $event_cost * $surcharge_amount / 100 : $surcharge_amount;
$surcharge = number_format( $surcharge, 2, '.', '' );
return $surcharge;
}
Would simply changing those numbers to 0 instead od 0.00 fix that?
I’d appreciate it however if there’s a way to change it so updates won’t destroy the changes.
Thanks.
Thanks Dean
So no way to change it permanently without updates affecting?
Maybe a simple option in an update?
Honestly, there are many countries when 100 currencies doesn’t equal 1.00x, but instead 100x.
No decimals. Considering the effort you made for compatibility with all the countries, I really think it would be worth it if currencies could be setup to their true value. Thanks.
I also would love to see this integrated into the core system. I maintain a site used in South Korea, and they have the same issue. Events typically cost 35,000 so the decimal causes confusion for the users.
To resolve this, I wrote a function “espresso_format_price” that outputs the price with the correct currency symbol, decimal and separator characters based on the country selected in organization options.
This solves the issue beautifully, but as you mentioned, I have to take time with each release to integrate the function back into the code.
I would be very happy to provide source code, diff files or whatever would be most helpful if you would consider adding this to the main code base.
As dbinc mentioned, this would be very helpful for a large number of countries including Korea, Japan, India, Taiwan, Mexico, Philippines, Hungary, Russia, Chile, and a number of others.
For sample usage, the following line…
In addition to the currency symbol parameter, you can also specify whether to display the separator. (Many countries use a comma instead of a period for their decimal separator.) For example, on a Russian receipt you may want to output the event cost of 12,000 Rubles.
$12.000 //(Twelve thousand in Russian)
$12,000.00 //(Twelve thousand in English)
I think you can probably see how this would cause confusion. The decimal separator flag gives you the option of including the separator when needed for output display.
Below is the full function code:
//Formats the price using the correct currency code and decimal places.
if (!function_exists('espresso_format_price')) {
function espresso_format_price($price, $show_symbol = true, $show_separator = true){
// Bail out if non-numeric value passed to function.
if (!is_numeric($price)){
return $price;
}
global $org_options;
/* ========================================================================
Set up decimal/separator exceptions.
(Countries that don't use dot for decimal and comma for separator.)
The following list was compiled from data on Wikipedia in June, 2011.
=========================================================================== */
switch (getCountryName($org_options['organization_country'])){
// Countries with comma as decimal and period as separator,
// and use relatively small currency values.
case 'Albania':
case 'Andorra':
case 'Argentina':
case 'Armenia':
case 'Austria':
case 'Azerbaijan':
case 'Belarus':
case 'Belgium':
case 'Bolivia':
case 'Bosnia':
case 'Herzegovina':
case 'Brazil':
case 'Bulgaria':
case 'Cameroon':
case 'Costa Rica':
case 'Croatia':
case 'Cuba':
case 'Cyprus':
case 'Denmark':
case 'Dominican Republic':
case 'Ecuador':
case 'Estonia':
case 'Faroes':
case 'Finland':
case 'France':
case 'Germany':
case 'Greece':
case 'Greenland':
case 'Honduras':
case 'Italy':
case 'Latvia':
case 'Lebanon':
case 'Lithuania':
case 'Luxembourg':
case 'Macau':
case 'Macedonia':
case 'Moldova':
case 'Netherlands':
case 'Norway':
case 'Panama':
case 'Paraguay':
case 'Peru':
case 'Poland':
case 'Portugal':
case 'Romania':
case 'Serbia':
case 'Slovakia':
case 'South Africa':
case 'Slovenia':
case 'Spain':
case 'Sweden':
case 'Tunisia':
case 'Turkey':
case 'Ukraine':
case 'Uruguay':
case 'Venezuela':
case 'Vietnam' :
$separator_code = '.';
$decimal_code = ',';
$small_currency = true;
break;
// Same as above, but use large currency values.
// (We can typically skip decimal places in display)
case 'Chile':
case 'Colombia':
case 'Czech Republic':
case 'Hungary':
case 'Indonesia':
case 'Iceland':
case 'Kazakhstan':
case 'Mongolia':
case 'Russia':
$separator_code = '.';
$decimal_code = ',';
$small_currency = false;
break;
// Countries with US type decimal and separator, but small currency values.
// (We can typically skip decimal places in display)
case 'Iran':
case 'South Korea':
case 'Sri Lanka':
case 'Pakistan':
case 'Mauritania':
case 'Nepal':
case 'Japan':
case 'India':
case 'Philippines':
case 'Thailand':
case 'Taiwan':
case 'Mexico':
$separator_code = ',';
$decimal_code = '.';
$small_currency = false;
break;
default:
// Everywhere else. (US, CA, AU and other countries)
$separator_code = ',';
$decimal_code = '.';
$small_currency = true;
break;
}
/* ====================================================================
Handle decimal fractions
(Some countries typically do not use decimals for currency.)
We will make an educated guess that if the price is over 1000,
and there is no fraction, we probably don't want any decimal.
Otherwise we will assume two decimal places as typical for USD.
==================================================================== */
if ($price - floor($price) == 0.00 && ((abs($price) >= 1000) or (!$small_currency))){
// No decimal places needed
$decimal_places = 0;
}
else{
// Show standard decimal.
$decimal_places = 2;
}
// Get currency symbol, if defined.
$cur_symbol = (isset($org_options['currency_symbol']) && $show_symbol) ? $org_options['currency_symbol'] : '';
// Clear separator if not desired.
$separator_code = $show_separator ? $separator_code : '';
// Return price formatted for display.
$formatted_price = $cur_symbol . number_format($price, $decimal_places, $decimal_code, $separator_code );
return $formatted_price;
}
}
That is pretty awesome! I will get this thread passed to the developers to have a look at and see if it is something that we could incorporate.
In my opinion it would need to be modified further, probably with some options to choose the thousand and decimal separator (e.g here in Finland the thousand is a space and the decimal a comma.)
Maybe we could bundle it as an addon.
I know that right now features like this are no longer being added into 3.1, but it is something we could look at for 4.0 and beyond.
Thank you Dean!
In the meantime I’ll follow your advice and edit the pricing.php file.
I’m sure a huge number of us from around the world will appreciate the feature being added in a future update.
There are 88 places in the plugin where the number_format function is used, and only a handful of them are in pricing.php. I’ll skip the ones in the individual gateways for brevity. Check these files:
gateways/process_payments.php
includes/admin-files/coupon-management/use_coupon_code.php
includes/admin-reports/edit_attendee_record.php
includes/admin-reports/enter_attendee_payments.php
includes/functions/cart.php
pricing.php(of course)
includes/process-registration/add_attendees_to_db.php
includes/process-registration/payment_page.php
templates/confirmation_display.php
templates/payment_page.php
Then there are some places such as templates/event_list_display.php where the price is displayed directly as it appears in the DB. Those may change after you make changes to all the above files and resave your prices, or you may want to consider just modifying your template files by wrapping the price displayed in a number_format function that will eliminate the decimals.
Sorry, I should have made my last suggestion more clear. It’s probably easier to find the places in the template files where the prices are displayed and wrap them in a number_format function. The event_list_display, registration_page_display, confirmation_page, payment_page, and payment_overview. I think that is about it.
Do you see it coming in a future update? ie choosing currency which would auto-update decimal points.
As for your last post, just for clarification, you’re saying change to $event_cost in those files you listed, correct?
Thanks.
Could you please tell me what should be changed in registration_page_display, confirmation_page, payment_page, and payment_overview? Basically all the ones you listed.
I think I’d like to do this, and then tell my clients never to update Event Espresso until an update with such features get introduced.
Thanks.
We can’t support custom code and therefore would not be able to give you line-by-line examples of what needs to be changed without a support token. What Sidney has suggested is finding all the occurrences of $event->event_cost and wrapping it in the number_format() php function. This can be done on the relevant templates by doing a search and replace.
I would also point out that doing so in either the template files or the gateway files does not mean that you would be unable to update Event Espresso (and we’d strongly advise that you didn’t recommend this to your clients) because your customizations would be done in the /wp-content/uploads/espresso/gateways and /wp-content/uploads/espresso/templates directories.
As another option for you, I have made these changes in my own slightly customized version of EventEspresso and I would be happy to provide a copy to you and anyone else that needs more extensive decimal/currency support. My version includes the following customizations to the core:
Added South Korean WON currency.
Support for Asian names that do not use the Western First/Last name format. (In my version last name is not a required field, and can be omitted from registration forms.)
Handling for decimal and separator issues in certain foreign currencies. (As described in a previous post.)
My current working version is updated to 3.1.31.2.P which was released today. If you are interested, feel free to send me an e-mail at: adam @ cadlinx.com
Hope this is helpful!
– Adam
Viewing 16 reply threads
The support post ‘How to get rid of decimals in prices’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.
Support forum for Event Espresso 3 and Event Espresso 4.