Format string by CultureInfo

后端 未结 5 1087
面向向阳花
面向向阳花 2020-12-03 00:30

I want to show pound sign and the format 0.00 i.e £45.00, £4.10 . I am using the following statement:

<%# Convert.To         


        
5条回答
  •  天命终不由人
    2020-12-03 01:21

    Use the Currency standard format string along with the string.Format method that takes a format provider:

    string.Format(new System.Globalization.CultureInfo("en-GB"), "{0:C}", amount)
    

    The CultureInfo can act as a format provider and will also get you the correct currency symbol for the culture.

    Your example would then read (spaced for readability):

    
        <%# string.Format(new System.Globalization.CultureInfo("en-GB"), 
                          "{0:C}", 
                          Convert.ToSingle(Eval("tourOurPrice")) 
                                 / Convert.ToInt32(Eval("noOfTickets")))
        %>
    
    

提交回复
热议问题