Magento 2 / Prices and subtotals with 4 decimals But VAT and Totals on 2 decimals - decimal

I had to change prices to 4 decimals and it's OK.
However, i have sometimes rounded cent in totals which is wrong. The explanation is that all calculations (subtotal, VAT and total) are on 4 decimals then rounded to 2 decimals.
With rounding, subtotal + VAT is sometimes different for 1 cent from total.
To fix this, i need to :
keep product prices to 4 decimals
keep subtotal calculate on 4 decimals then rounded it to 2 decimals
calculate VAT and total from this rounded subtotal and not from the 4 decimals subtotal.
But i can't figure how to do this.
I tried multiple solutions and nothing is working : even with forcing subtotal/VAT and saving, it seems to be calculated again elsewhere and 4 decimals appear again.
Can you give me some piece of advice on how to achieve this ?
Thanks !

I succeed in rewriting event sales_quote_collect_totals_after
I will post the code of my module ASAP

Related

Excel increase / decrease decimal based on kg/gr

In my sheet I'm weighing 4 samples. I need to report the average of these samples so I've written a simple function. However for customer #1 I need to report them in KG's with 1 decimal and to customer 2 I need to report them in Gr's with 0 decimals. So I wrote the formula below:
=IF(test="customer#1";ROUND(AVERAGE(M26:O29);1);ROUND(AVERAGE(M26:O37);0);
This calculates the values correctly however the GR's still display 1 decimal (.0) even though it doesn't get calculated. Is it possible to tell Excel to subtract a decimal when using grams but add it when using kilograms.
I've tried to with conditional formatting which displays the correct number but the decimal is still "hiding" beneath the surface.

convert, round, and multiply/divide in excel

We're doing an overtime incentive where people can earn raffle tickets based on the number of extra hours they work. They earn one ticket for every seven hours of overtime they work. I've built an excel sheet that I can just import the total hours into to track this, but I'm having trouble with the "number of tickets earned" formula.
I have a column for the number of hours over 40 worked, then a column to convert the hours to a number then divide by seven using: =((C2-INT(C2))*24)/7. Next column, I have =ROUNDDOWN(D2, -0.5) because if they worked 15 hours, it was giving them 2.5 tickets.
The issue I'm running into is that when they worked exactly 7 hours, I get 0 for the =ROUNDDOWN(D2, -0.5) formula. I tried =ROUND(D18, -0.5) but if they worked 6 hours 30 minutes, it gives them one ticket. I'm sure I'm probably missing something simple but is anyone able to help?
You have already used INT, which would be a better option than ROUND or ROUNDDOWN. Also C2-INT(C2) can be simplified to MOD(C2,1):
=INT(24*MOD(C2,1)/7)
Breaking it down:
MOD(C2,1) take the decimal portion of C2 (i.e. Hours, less than 24)
24*MOD(C2,1) convert from fraction-of-day to full hours
24*MOD(C2,1)/7 divide by 7. For 6.5 this gives 0.928... and for 15 it gives 2.142...
INT(24*MOD(C2,1)/7) take only the Integer part. For 6.5 this gives 0, for 15 it gives 2
I think your problem is the -0.5 argument of the ROUNDDOWN function. Why do you want to round to negative one half decimal places?
Just use ROUNDDOWN(D2,0).
Edit: I'm not sure why Agent 7 and Agent 8 have different numbers of tickets if they both worked exactly 7 hours overtime. Is the 7:00 a rounded number?
Assuming overtime is in column C, you could use:
=ROUND((HOUR(C1) + IF(MINUTE(C1)<30,0,1)) / 7, 0)
This should yield the correct number of tickets if you want to round up the hour when they are over 30 minutes. Otherwise, you could just take out the IF / MINUTE section and it will only count complete hours.

PowerPivot displaying rounded result

I have created a PowerPivot Report which contains a Price field and a Sales as well as a Measure column.
Price Column will obviously contain the unit price
Sales Column will give the units sold
Measure Column is the measure of the product.
From this I have a:-
Total Price which is PricexSale and a
Total Measure which is MeasurexSale
In the calculation section I have then worked out a calc which is Simply
Unit Per Thousand:=SUM(Products[Total Price])/SUM(Products[Total Measure])*1000
The issue I am getting is this is rounding it to the nearest 10 So rather than £17.88 it is displaying £17.90. It is set to 2 decimal places already. All the values in the columns are correct to the 2 decimal places. Can anyone assist to get me the correct result and not a rounded result.
It sounds like you need to use the round function in DAX on your measure which would allow you to round the result of the calculation. This being different then setting the field's format settings.
It would be
ROUND(<number>, <num_digits>)
Link to Microsoft site on the function:
enter link description here
Edit:
Then it sounds like you want to use the trunc function in DAX to truncate the number after a certain number of significant digits.
TRUNC(<number>,<num_digits>)

Use MS Excel to round one number to 2 significant figures, then update another cell to match the number of decimal places

I am trying to use Microsoft Excel to format a large set of data. The data is all in decimal format and the results are paired so that we have 2 values per record. The first value is a Mass in grams, and the second value is the Uncertainty of that mass also in grams.
For example:
SampleName = S1, Mass(g) = 28.695, Uncertainty(g) = 1.601133
What I need to do is have the "Uncertainty" update to 2 significant figures, then depending on the value returned, have the "Mass" update to match the number of decimal places (or whole numbers) that the "Uncertainty" now is.
e.g.
if Uncertainty became 1.6, then Mass should become 28.6
if Uncertainty became 1.61, then Mass should become 28.69
if Uncertainty became 2, then Mass should become 29
I have attempted to use the ROUND function on the "Uncertainty" cell but then I don't know how to make the "Mass" cell update accordingly.
I have tried the following 2 ROUND formulas, which both seem to work for rounding the "Uncertainty":
=ROUND(A1,2-INT(LOG(ABS(A1))))
=ROUND(A1, 2)
Any help would be much appreciated.
This formula counts the number of decimal places in a given cell:
=LEN(RIGHT(A1,LEN(A1)-FIND(".",A1)))
So you could use this in your Round formula where you specify the number of decimals:
=ROUND(A1, LEN(RIGHT(A1,LEN(A1)-FIND(".",A1))))
To round to 2 significant figures you can use something like this:
=ROUND(uncertainty,2-(1+INT(LOG10(ABS(number)))))
To round (eg) B2 based on number of decimals in (eg) D2:
=ROUND(B2,IFERROR(LEN(RIGHT(D2,LEN(D2)-FIND(".",D2))),0))

Why does excel AVERAGE change when changing the number format of cells?

I've got an Excel sheet which is exhibiting strange behaviour. I have 2 values, followed by an average of those 2 values - simple enough, right?
However, if I change the number format of the top cell from 2 decimal places to 30, I get a different result:
Can anyone explain this? When a cell is formatted to 2 decimal places, does that mean all formulae using this cell are rounding the value to 2 decimal places also?
Check your Excel options (Alt+F,T) for the Advanced ► When calculating this workbook ► Set precision as displayed option. When this is checked, calculation is automatically rounded off to the displayed number of decimals rather than the internal 15 digit floating point precision. It also permanently truncates the raw value to the displayed precision so I am unclear on how you are bouncing between the two average values.
The actual average of 1.6786427146 and 1.73 is 1.7043213573 which is 1.70 when only two decimals are displayed. It would only be through Precision as displayed that 1.6786427146 would actually be converted to 1.68 making the average 1.71.
Turn the option off and the underlying raw value will be stored to a 15 digit floating point precision. The same goes for all internal formula calculations.

Resources