News:

Looking for documentation? Take a look on our wiki

Main Menu

Price rounding just works after the decimal point

Started by hazael, October 28, 2022, 12:02:36 PM

Previous topic - Next topic

hazael

Price rounding just works after the decimal point

if i have a price: 12345.6789
i want a price 12300
I can only have 12346

In virtuemart configuration, a negative value (-2) does not change anything.
I tried to add a negative value in the currency settings - I managed to round it there, but there was a bug on the site. The basket stopped working - it does not increase the price when I add another item

Milbo will write in a moment that "it is illogical, because you can enter this price manually". But what to do when I have different discounts?  ;D
In this case, is it is possible just a manual modification in PHP and javascript?

Virtuemart 4.0.7.x

Jörgen

You should look up rounding rules, your example is wrong.

try this:

echo(round(12345.67789/100)*100 . "<br>");

Should give 12300

Jörgen
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Milbo

Quote from: hazael on October 28, 2022, 12:02:36 PM
if i have a price: 12345.6789
i want a price of 12400
I can only have 12346

12345.6789 rounded to one digit 12345.7, to zero digits 12346, to -1 digit 12350, but I think negative rounding is not accepted. It actually means, "use the rounding of the currency". Because you need in a multicurrency system different roundings per currency.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sirius

For example in Europe so for EUR currency, the amounts in euros are expressed with two digits after the decimal because the smallest subdivision will be the "cent" of the euro.

We recall here the main articles, concerning the conversion process, of the draft Community regulations on the introduction of the euro, politically validated at the Dublin European Council in December 1996.

https://www.economie.gouv.fr/dgfip/arrondis#IA
J3.10.12 | PHP 7.4.33 + APC + Opcode
VM Prod : 3.8.6 | VM Test : 4.4.0.11095

hazael

#4
Quote from: sirius on October 28, 2022, 13:15:11 PM
For example in Europe so for EUR currency, the amounts in euros are expressed with two digits after the decimal because the smallest subdivision will be the "cent" of the euro.

You buy a car for 52000,- Euro - have you seen someone put up a car for 51625.35 Eur? That seller will be laughed at :)

For example: 52000;- is my starting price. But now I'm doing a 13% discount and we have an ugly price: 45240,- 
Such a  rounded price is pleasing to the eye and easy to remember: 45000;-



hazael

#5
Quote from: Milbo on October 28, 2022, 13:02:32 PM
use the rounding of the currency
That's exactly what I did - I rounded the currency with value [-2] and there was a problem.
adding more items in the cart stopped working - is blocked.

JS Error:
RangeError: .toFixed() digits argument must be between 0 and 100

In this case, I think the only sensible way is to round these prices with javascript directly on the product page :(



Quote from: Jörgen on October 28, 2022, 12:34:27 PM
You should look up rounding rules, your example is wrong.
Yes you are right. I corrected. For example, I came up with this rounding (from my mind) and I made a mistake by 1. But as you already know - there is another problem. :)

Milbo

Quote from: hazael on October 28, 2022, 15:35:02 PM
In this case, I think the only sensible way is to round these prices with javascript directly on the product page :(

VM should prevent that for security reasons. Btw, your js error is not from vanilla vm. This variable "updateSumPrice_new" does not exist in VM. There is also no emptyQuantity.

Please create a vanilla installation and if you report a bug, check if the bug exists on the vanilla installation.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sirius

Quote from: hazael on October 28, 2022, 15:10:26 PM
Quote from: sirius on October 28, 2022, 13:15:11 PM
For example in Europe so for EUR currency, the amounts in euros are expressed with two digits after the decimal because the smallest subdivision will be the "cent" of the euro.

You buy a car for 52000,- Euro - have you seen someone put up a car for 51625.35 Eur? That seller will be laughed at :)

For example: 52000;- is my starting price. But now I'm doing a 13% discount and we have an ugly price: 45240,- 
Such a  rounded price is pleasing to the eye and easy to remember: 45000;-
Yes I've already seen such a price (and the world is not only with cars) and so in this case the price would be 51999 not 52000 that's what it should be for a magical price, so 45239 in your case :)
That's your point of view.
Nothing ugly there...a price is a price.
J3.10.12 | PHP 7.4.33 + APC + Opcode
VM Prod : 3.8.6 | VM Test : 4.4.0.11095

hazael

#8
Quote from: sirius on October 28, 2022, 17:43:11 PM
Yes I've already seen such a price (and the world is not only with cars) and so in this case the price would be 51999 not 52000 that's what it should be for a magical price, so 45239 in your case :)
The magic low prices 99,99 is only in Lidl and Media Markt ;-)
My site sells houses. Nobody cares about euro cents when you sell a house for 1 million. This is a slightly different client sector - intended for serious construction developers instead of market idiots who count every penny  :)

Quote from: Milbo on October 28, 2022, 17:11:08 PM
Please create a vanilla installation and if you report a bug, check if the bug exists on the vanilla installation.
Ok Milbo, it may be as you write. In my spare time, I will test the VM on a clean install


sirius

That's what I said, it's your POV because it's YOUR market, no need to be contemptuous towards others.
J3.10.12 | PHP 7.4.33 + APC + Opcode
VM Prod : 3.8.6 | VM Test : 4.4.0.11095

hazael

#10
Without exaggeration. I despise no one. Maybe my jokes are received differently in each country. :)
I have several stores and the current solution is enough for me. But sometimes there are problems like this one

hazael

#11
Quote from: Milbo on October 28, 2022, 17:11:08 PM
This variable "updateSumPrice_new" does not exist in VM. There is also no emptyQuantity.
Okay, Milbo. You were right. I found the culprit. The old plug "CATPRODUCT" broke everything
https://extensions.virtuemart.net/product/products/catproduct-detail
I fixed this script.
The topic can be closed - everything works beautifully :)