I am developing a POS application for a medical store using C#. As per the store requirements, they have two types of products.

1. Products without variations (Do not have sub-products i.e. A bottle of suspension or baby food).
2. Products with variations (Have sub-products i.e. A Packet of tablets-> Have 3 Strips -> Each strip contain 10 tablets)

For products with variations, I have the variation standard (Every product has a specific quantity of strips within each packet and each strip has a specific amount of tablets). I have managed them with levels. i.e. Level A (For parent product), Level B (For sub-item e.g. strips within a packet), Level C (For single tablet within a strip). I have managed products with variations like this in order to speed up the sale-out operation.

According to customer behavior, I want to manage the sale operation such that if a customer purchases a packet of tablets and the packet contain 3 strips and each strip further contain 10 tablets, I want to fully capture this stock reduction in my database.

I have a separate table in my SQLServer for this purpose. The table contains both products (with and without variations). The table also contains a separate field called IsParent for tracking products. The IsParent field stores 0 for Products without Variations and 1 for Products with Variations. The table also contains separate fields for each Level of a variation based product and a separate quantity field for each level.

Suppose I have 10 packs of XYZ tablets and it's Level B Standard is 3 (3 strips in each pack) and it's Level C standard is 10 (10 tablets in each strip), then my existing stock will be something like this:

10 X 3 = 30 strips

30 X 10 = 300 tablets

Now, if a customer purchases a single strip out of those 10 packets then how can I subtract 1 strip from the whole stalk i.e 30 strips? And how can I subtract those 10 tablets (1 strip) from the whole stalk i.e. 300 tablets?

Until now, I am doing the following manual subtraction:

For Level B (a single or two strips each having 10 tablets)

```
decimal levelB = purchaseQuantity / levelBStandard;
decimal levelB_Qty = Math.Round((Decimal)levelB, 1);

```

The purchase quantity is the quantity that a customer has purchased. This quantity is divided by the level B standard i.e. 3. If a customer purchase 2 strips, then `2/3 = 0.66` and if a customer purchase 1 strip, then `1/3 = 0.33`. If another customer will purchase a single or two strips from the same product, then the stock amount will go tricky after a few transactions due to the decimal point.

I am also doing the same operation if a customer will purchase less than 10 tablets which are quite tricky for me. I need some way to manage this stock reduction such that if 2 strips are sold out from `30 strips` in one sale operation, then the remaining stock quantity will be `29.34 or 29.3`. Later, in another sale operation of the same product, if another customer purchase a single strip, then the stock amount of strips should become `29` instead of `29.01` because this `0.1` is creating problems for me.

I will be managing the stock reduction for tablets in the same way as well. I hope somebody may help me with a simple but reliable solution. Any help will be extremely appreciated.