# Stuck on 'CashOnDelivery' code

## Recommended Posts

Im trying to customize a COD module to fit my needs.

This is the piece of code

`\$order->total_shipping_tax_excl = (float)\$this->context->cart->getPackageShippingCost((int)\$id_carrier, false, null, \$order->product_list)+\$fee;`

At the end of the line I need

`\$fee/1.21`

but it throws an error.

But if I use

`\$fee*AnyNumberHere`

it woks but obviously it is not the result I need.

Why can I multiply but not divide?

Im using PS 1.6.0.14.

Edited by dogdayfear (see edit history)
##### Share on other sites

I'm not sure why you can't divide. Perhaps you need to use brackets like (\$fee / 1.21)? Or maybe you need to convert fee to a float like ((float)\$fee / 1.21)? If neither of those work, you can use simple algebra to convert it into multiplication, i.e. (\$fee * (1 / 1.21)) or (\$fee * 0.8264462809917355).

##### Share on other sites

Hi rocky!, thanks so much for answering.

- If I use brackets -> Error.

- I tried converting to float -> Error.

After that I give it a try to algebra and that give a little light:

(\$fee *  (1 / 1.21)) -> Error.

(\$fee * 0.8264462809917355) -> ERROR TOO!

So I think its about decimals used.

In terms of decimals I can divide by 1.2 and can multiply by 0.8264462. If I use more decimals it throws the 500 server error.

Can you figure out what is happening?

Thanks again.

##### Share on other sites

Interesting. Let's see if rounding the number will help. Try the following:

Tools::ps_round(\$fee / 1.21, 2)

This should round the value to two decimal places before adding it.

##### Share on other sites

Hey rocky!

That solved the problem!!! Thank you so much.

But Im very intrigated abou why some number of decimals work for multiplying and other different number of decimals for dividing.

Very confussing for me ...

## Create an account

Register a new account