Hey all,
If you are like me and prefer a more classic currency system using Gold Pieces or something you were probably annoyed with this being set up with floats when you only need ints. However, you still want to fine tune discounts. I have found the best way to do this is with int casting and Math.Round. It seems to be working fairly well for me, but someone smarter may be able to find a way to make it more accurate. So here is my code for GetPrice:
private int GetPrice(StockItemConfig config)
{
if(isBuyingMode) return (int)Math.Round(config.item.GetPrice() * (1 - config.buyingDiscountPercange / 100)); //Apply buying discounts
return (int)Math.Round(config.item.GetPrice() * (sellingPercentage / 100)); //Apply sell penalty
}
I apologize for the single line if statements. I much prefer them if there really is only one line to worry about. I use 90% zoom on a 1440p monitor so I have all the room in the world.
Now as far as displaying the prices(the :n0 does similar to the n2 with the currency type that Sam used, just this displays no decimals but adds the commas for thousands, millions, etc):
public void Setup(Shop currentShop, ShopItem item)
{
//All the other stuff
priceField.text = $"{item.GetPrice():n0} G";
}