Support » Plugin: WooCommerce » Wrong round in cart and checkout

  • Resolved emporio3

    (@emporio3)


    Hi,
    i set a fixed price 20€ and i set taxable and i set tax is included. Tax is standard and it is 22%
    Now in cart and checkout there is an error in round i see:

    EXAMPLE
    product: 1235,00
    shipping: 55,00
    fixed fee: 20,00

    TOTAL: 1309,99 (included 236,23)

    WHY 1309,99 and not 1310??

    If i set 4 number after comma i can see 20€ become 19,9958…..why woocommerce have 19,9958€ instead 20€ ?? I set 20€

    If i set 1 number after comma all works fine

    Could someone help us?

    We have last woocommerce

    Thanks

Viewing 11 replies - 1 through 11 (of 11 total)
  • Could someone help us please?

    Thanks in advance

    Plugin Support Joel Williams

    (@joelwills)

    Automattic Happiness Engineer

    Hi there!

    I believe this his is because we use four decimal places but show two.

    I assume you’re adding prices including tax. To solve this you can enter prices excluding tax (change the setting under WooCommerce > Settings > Tax and change the prices).

    It has to work backwards as you’re entering prices including tax and then setting the tax.

    For example, the product is 1235 inc 22% tax.

    That means the product price before tax is 1235/1.22 = 1012.2590

    So the tax is 1235 – 1012.2590 = 222.741

    1012.2590 + 222.741 = 1235 so that’s correct for the product, but you have shipping and a fixed fee too.

    We do the same for shipping and the fixed fee we get

    Product: 1012.2591
    Product Tax: 222.741
    Total: 1235

    Shipping: 45.0819
    Shipping Tax: 9.9180
    Total: 54.9999

    Fixed Fee: 16.3934
    Fixed Fee tax: 3.6065
    Total: 19.9999

    So adding those all together:

    1235 + 54.9999 + 19.9999 = 1309.9998

    We then show two decimal places so 1309.99

    As mentioned, to solve this you can add prices/shipping excluding tax and set it so the right amount appears for the product using four digits (you can still display two digits).

    Hope that helps!

    Hi,

    we knew that to solve we can use price without tax……
    We were looking for a different solution cause we can’t do that…Is there another way to round up?

    Plugin Support Joel Williams

    (@joelwills)

    Automattic Happiness Engineer

    There isn’t an inbuilt way to do this I’m afraid, you’d need to custom code this.

    My sympathies. My site was giving a total 0.01 too much. I don’t think Woo has this right: 1309.9998 should show as 1310.00 not 1309.99.

    This fixed my problem:

    add_filter( 'woocommerce_calculated_total', 'custom_calculated_total' );
    function custom_calculated_total( $total ) {
      $total = round( $total, 1 );
      return $total;
    }
    Plugin Support Hannah S.

    (@fernashes)

    Automattic Happiness Engineer

    Thanks for that solution, @lorro!

    I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

    @hannah S

    The issue is not resolved. It seems a small number of stores are experiencing rounding errors. My solution is just a fudge to keep us going.

    Its easy to spot on my site because everything costs something.00, so a final bill of something.01 shouts out as wrong to customers. I think the developers need to look at rounding a bit longer.

    @lorro, where did you add that code to fix this?

    It can go in functions.php for your child theme. If you don’t have a child theme, you can try the “My Custom Functions” plugin. Please note this code snippet is for my site where everything costs something.00. Its not likely to be a general fix.

    Thanks a lot @lorro. It solved my problem. I also just have products that end with 00 so that’s perfect.

    But still, there should be an official fix for this problem because it affects two of my shops!

    Cheers
    Martin

    I use this code:

    // Round price for .99 .01 decimals
    add_filter( 'raw_woocommerce_price', function ( $price ) {
    	$decimals = round( $price - floor( $price ), 2 );
    
    	return ( $decimals == 0.01 || $decimals == 0.99 ) ? round( $price ) : $price;
    } );

    As @lorro says this code snippet is for sites where everything costs XXX.00

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Wrong round in cart and checkout’ is closed to new replies.