# How do I add the Litium logic for currency for a decimal value

**URL:** <https://forum.litium.com/t/how-do-i-add-the-litium-logic-for-currency-for-a-decimal-value/414>\
**Category:** Questions\
**Tags:** litium-6, accelerator\
**Created:** [December 6, 2018, 9:39am UTC](https://forum.litium.com/t/how-do-i-add-the-litium-logic-for-currency-for-a-decimal-value/414 "2018-12-06T09:39:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cissi](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/cissi/32/18_2.png) [@Cissi](https://forum.litium.com/u/Cissi)\
**Post date:** [December 6, 2018, 9:39am UTC](https://forum.litium.com/t/how-do-i-add-the-litium-logic-for-currency-for-a-decimal-value/414/1 "2018-12-06T09:39:46Z")

</div>

We have a price that is “price without vat”. And that price I need to set with the decimal

So I can use it on items like this Model.CampaignPrice (CampaignPriceItem). But this is a price with vat. So if I want the price without vat I add Model.CampaignPrice.Price (decimal). But then I cant use the logic to get the format set in Litium.

Litium version: 6.2.2

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [December 6, 2018, 4:22pm UTC](https://forum.litium.com/t/how-do-i-add-the-litium-logic-for-currency-for-a-decimal-value/414/2 "2018-12-06T16:22:48Z")

</div>

If I understand you correctly your prices is including VAT and you want to use the inbuilt logic to display them?

If you in that case create an own price-item-class; example

```auto
    public class PriceItemWithVat : ProductPriceModel.PriceItem
    {
        public PriceItemWithVat(decimal minimumQuantity, decimal price, decimal vatPercentage)
            : base(minimumQuantity, decimal.Zero, vatPercentage)
        {
            PriceWithVat = price;
            Price = price / (1 + vatPercentage);
        }

        /// <summary>
        /// Gets or sets the price.
        /// </summary>
        /// <value>The price.</value>
        public override decimal Price { get; set; }

        /// <summary>
        /// Gets the price with vat.
        /// </summary>
        /// <value>The price with vat.</value>
        public override decimal PriceWithVat { get; }
    }

```

And then adding the following methods to the builder that is creating your price

```auto
        private string Format(decimal amount, bool displayCurrencySymbol, Currency currency)
        {
            NumberFormatInfo numberFormat;
            if (!displayCurrencySymbol)
            {
                numberFormat = (NumberFormatInfo)currency.GetNumberFormatInfo(CultureInfo.CurrentUICulture).Clone();
                numberFormat.CurrencySymbol = string.Empty;
            }
            else
            {
                numberFormat = currency.GetNumberFormatInfo(CultureInfo.CurrentUICulture);
            }
            return amount.ToString(currency.TextFormat, numberFormat).Trim();
        }

        private T SetFormattedPrice<T>(T item, Currency currency) where T : ProductPriceModel.PriceItem
        {
            var price = _cart.IncludeVAT ? item.PriceWithVat : item.Price;
            item.FormatPrice = x => Format(price, x, currency);
            return item;
        }

```

you can construct your prices like this

```auto
    var price = new PriceItemWithVat(0, 125, 0.25);
    SetFormattedPrice(price, currency);

```

And after that the rendering page should work without any modifications.

---

<div class="post-metadata">

**Author:** ![Cissi](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/cissi/32/18_2.png) [@Cissi](https://forum.litium.com/u/Cissi)\
**Post date:** [December 6, 2018, 4:40pm UTC](https://forum.litium.com/t/how-do-i-add-the-litium-logic-for-currency-for-a-decimal-value/414/3 "2018-12-06T16:40:40Z")

</div>

Yes and no. I use the built in to display prices, but they are all with vat. So when I’m displaying it without vat there is no built in method in the accelerator to use the same logic that I use for thoose with vat.

For example:  
I write this to get campaign price with vat:  
@Model.ProductItem.Price.CampaignPrice.FormatPrice() in ProductWithVariants.cshtml  
but without vat I need to write @Model.ProductItem.Price.CampaignPrice.FormatPrice.Price but then it becomes an decimal so I can use FormatPrice().

But still, I can use your answer for this anyway! 🙂 Thank you
