Format A Number Into A Currency String

admin 236 0

In C#, you can use the `.()` method to format the output string. This method uses a placeholder-like method to specify a specific portion of the output string. Here is a simple example: ``` num = 10; name = "John"; price = 12.5; = .("The item is {0}, the name is {1}, and the price is {2:C}.", num, name,price);.();```The output result is: `` ` is 10, the name is John, and the price is $12.50. ``In the above code, `{0}`, `{1}` and `{2}` are placeholders for the first, second and third respectively in the parameter list parameter. The "C" after the colon means formatting the "price" parameter into currency form. In addition to the formatting methods in the above examples, there are other commonly used formatting options, such as date and time formatting, number formatting, etc. You can refer to the C# documentation for more information.

标签: #currency

  • 评论列表

留言评论