'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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source