Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Hugh 30 posts 64 karma points
    Jan 30, 2014 @ 15:03
    Hugh
    1

    Partial View Currency Format

    Hi all

    I am displaying an integer as a string and adding a $ to the start of the string to show that it is a currency.

     @if (p.GetPropertyValue<string>("salePrice") == "0")
                    {
                        <span class="price">TBA</span>
                    }
                    else
                    {
                       <span class="price">[email protected]("salePrice")</span>
                    }

     

    I was wondering if there is a way to format the saleprice directly to a currency format.

    Thanks in advance

    Hugh

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 30, 2014 @ 17:12
    Jeavon Leopold
    1

    Hi Hugh,

    Assuming you are storing salePrice as a TextString but entering decimal values (maybe validating with regex?) then this should work ok:

    @{
        var salePrice = p.GetPropertyValue<decimal>("salePrice");
        if (salePrice == 0.00m)
        {
            <span class="price">TBA</span>
        }
        else
        {
            <span class="price">@string.Format("{0:C}", salePrice)</span>
        }
    }
    

    C is the currency format specifier, see here for more info

    Jeavon

  • BJ Patel 80 posts 206 karma points
    May 06, 2016 @ 09:53
    BJ Patel
    2

    Hi Hugh,

    it tool late for you but may be helpful to someone else,

    what I have done is that

          @if (CartProductNode.HasValue("salePrice"))
            {
            decimal ProdsalePrice;
            decimal.TryParse(CartProductNode.GetProperty("salePrice").Value, out @ProdsalePrice);
    
            $ @ProdsalePrice.ToString("0.00")
    
            }
    

    BJ,

Please Sign in or register to post replies

Write your reply to:

Draft