Support

Home Forums Event Espresso Premium How to get rid of decimals in prices

How to get rid of decimals in prices

Posted: April 4, 2013 at 1:17 am

Viewing 16 reply threads


dbinc

April 4, 2013 at 1:17 am

Hi
The currency I’m using does not use xx.00 decimal points. Just whole numbers.
Is it possible to get rid of the decimal points?
Thanks as always.


dbinc

April 4, 2013 at 1:22 am

Is it this bit?(pricing.php)

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.


Dean

April 4, 2013 at 2:27 am

Sorry if this ends up being a duplicate I thought my answer went through earlier.

Basically you will need to find in the pricing.php the following:

$event_cost, 2, '.', ''

and

$event_cost, 2

and edit them to just show

$event_cost

Of course editing a core file is not recommended and any updates will over write your changes.


dbinc

April 4, 2013 at 12:56 pm

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.


Adam

April 4, 2013 at 4:09 pm

Dear dbinc and Dean,

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…

$event_cost = $org_options['currency_symbol'] . $result->event_cost;

Becomes…

$event_cost = espresso_format_price($result->event_cost);

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;
    }
}


dbinc

April 4, 2013 at 8:46 pm

Wow, good stuff Adam!
Hopefully Dean and his co-workers will recognise the need for a whole lot of us to get this feature.


Dean

April 5, 2013 at 6:11 am

Hi Adam,

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.


dbinc

April 5, 2013 at 6:14 am

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.


dbinc

April 6, 2013 at 1:46 am

Hmm..
Dean, I replaced all of the

$event_cost, 2, '.', ''

and

$event_cost, 2
to

$event_cost

Yet nothing changes…


Sidney Harrell

April 7, 2013 at 8:03 pm

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.


dbinc

April 8, 2013 at 12:00 am

No way am I doing all that.


Sidney Harrell

April 8, 2013 at 10:52 am

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.


dbinc

April 8, 2013 at 11:53 am

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.


Sidney Harrell

April 8, 2013 at 12:49 pm

Not necessarily. Take a look at templates/event_list_display.php line 70. Right now it just has:

<p id="p_event_price-<?php echo $event_id ?>" class="event_price"><span class="section-title"><?php  echo __('Price: ', 'event_espresso'); ?></span> <?php echo  $org_options['currency_symbol'].$event->event_cost; ?></p>

To make it have no decimals, you would change it to:

<p id="p_event_price-<?php echo $event_id ?>" class="event_price"><span class="section-title"><?php  echo __('Price: ', 'event_espresso'); ?></span> <?php echo  $org_options['currency_symbol'].number_format($event->event_cost); ?></p>

Take a look at the manual page here: http://php.net/manual/en/function.number-format.php


dbinc

April 8, 2013 at 3:06 pm

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.


Chris Reynolds

  • Support Staff

April 17, 2013 at 10:56 am

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.


Adam

April 24, 2013 at 4:56 pm

Hi dbinc,

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.

Event Espresso