dogdayfear Posted March 14, 2015 Share Posted March 14, 2015 (edited) 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. Thanks in advance. Edited March 14, 2015 by dogdayfear (see edit history) Link to comment Share on other sites More sharing options...
rocky Posted March 15, 2015 Share Posted March 15, 2015 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). Link to comment Share on other sites More sharing options...
dogdayfear Posted March 15, 2015 Author Share Posted March 15, 2015 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. Link to comment Share on other sites More sharing options...
rocky Posted March 16, 2015 Share Posted March 16, 2015 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. Link to comment Share on other sites More sharing options...
dogdayfear Posted March 16, 2015 Author Share Posted March 16, 2015 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 ... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now