Slth com
Slth com

Reputation: 59

Woocommerce price * quantity multiplication decimal issue

I have some codes below that I share. I do price * quantity. Everything is good, however, If the result is XX,00 decimals do not appear. If the result is XX,15 decimals appear.

$quantity   = apply_filters( 'woocommerce_cart_item_quantity', $cart_item['quantity'], $cart_item_key, $cart_item );
$price      = (float) wc_get_price_to_display( $product );
$result     = $quantity * $price; 

As you understand. If the result is 12.15$ I can see decimals. If the result is 12.00$, I can't see decimals.

Upvotes: 2

Views: 184

Answers (1)

NickolaS
NickolaS

Reputation: 124

that is because float doesn't show 0 ending decimals. Else you would see 12.15000... for example

So, use number_format

in your case it is

$result=number_format($quantity*$price,2,'.','');

enter image description here

Upvotes: 4

Related Questions