locked
2 decimal place in C# RRS feed

  • Question

  • User-240513752 posted

     Price = currencyCode + " " + ci.Price

    there can any decimal value in ci.Price. but it is without any dot,
    i have to apped a dot with two zeros

    like

    100->100.00

    24->24.00

    999->999.00

    Thursday, October 26, 2017 10:04 AM

All replies

  • User-1768369891 posted

    like as "USD 128"->"USD 128.00"

    If you variable is not string type then you can use this 

    <td>@courseInstance.Price.ToString("00.00")</td>

    Or If it is string type or other type then used string.Format method to convert value as your desired format.

    <td>@string.Format("{0:C}", courseInstance.Price).Replace("$","USD ")</td>

    Thursday, October 26, 2017 10:40 AM
  • User-335504541 posted

    Hi khan_1,

    I think you could also try to use:

    ci.Price.ToString("n2");

    Best Regards,

    Billy

    Friday, October 27, 2017 9:35 AM
  • User1718151756 posted

    Try this:

    Price = String.Format("{0} {1:n2}", currencyCode, ci.Price);

    Thursday, November 2, 2017 11:52 AM