Format a String as Currency in C# Format ng isang String bilang Currency sa C #
When building a string for output to a web page, it's useful to format any currency value in a human-friendly money format. Kapag ang gusali ng isang string para sa output sa isang web page, ito ay kapaki-pakinabang sa format ng anumang halaga ng pera sa isang tao-friendly ng pera na format. This is extremely easy in C#. Ito ay lubhang madali sa C #.
The system format string works like this: {0:C} Ang sistema ng string ng format ng mga gawa tulad nito: (0: C)
For example, the following code example: Halimbawa, ang sumusunod na halimbawa ang code:
decimal moneyvalue = 1921.39m; decimal moneyvalue = 1921.39m; string html = String.Format(" Order Total: {0:C} ", moneyvalue); string html = String.Format ( "Order Total: (0: C)", moneyvalue); Console.WriteLine(html); Console.WriteLine (html);
Outputs the following: Outputs ang mga sumusunod:
Order Total: $1,921.39 Order Total: $ 1,921.39
It's worth noting that you must pass in a numeric value to the String.Format statement. Ito ay nagkakahalaga ng pagpuna na dapat mong ipasa sa isang numerong halaga sa pahayag String.Format. If you pass in a string value, it won't format correctly. Kung pumasa ka sa isang string na halaga, ito ay hindi na format ng tama. If your currency value is in a string, you need to convert it into a double first. Kung ang iyong halaga ng pera ay isang string, kailangan mong i-convert ito sa isang double muna.

Daily Email Updates Araw-araw na Updates Email
You can get our how-to articles in your inbox each day for free. Maaari kang makakuha ng aming kung-paano na mga artikulo sa iyong inbox sa bawat araw para sa libre. Just enter your name and email below: Ilagay lamang ang inyong pangalan at email sa ibaba:



You can also use: Maaari din ninyong gamitin:
decimal moneyvalue = 1921.39m; decimal moneyvalue = 1921.39m;
string html = “Order Total: ” + moneyvalue.ToString(”C”); string html = "Order Total:" + moneyvalue.ToString ( "C");
Console.WriteLine(html); Console.WriteLine (html);
how do i format the currency value ie from $ to £ that isd from dollars to pounds using the string.format ? paano ko i-format ang pera ibig sabihin na halaga mula sa $ £ na isd dolyar mula sa pounds gamit ang string.format?
I can give help I think look at control panel , regional option and look you can change your currency value there Maaari ko bang magbigay ng tulong sa tingin ko ay tumingin sa control panel, rehiyonal na opsiyon at hanapin maaari mong palitan ang iyong pera may halaga
Ultimate one ..really helpful Ultimate isa .. talagang helpful
decimal moneyvalue = 1921.39m; decimal moneyvalue = 1921.39m;
You can use Maaari mong gamitin ang
moneyvalue.ToString(”N”) moneyvalue.ToString ( "N")
instead of sa halip ng
moneyvalue.ToString(”C”) moneyvalue.ToString ( "C")
by this way you get the formatted string just like currency, without Currency sign sa pamamagitan ng ganitong paraan makuha ninyo ang mga format na string tulad ng pera, walang mag-sign Currency
by this way you get the formatted string just like currency, without Currency sign sa pamamagitan ng ganitong paraan makuha ninyo ang mga format na string tulad ng pera, walang mag-sign Currency
thanks i searching about this thanks ako tungkol sa paghahanap na ito
Thanks for a great article, direct and to the point! Salamat sa isang mahusay na artikulo, direktang at sa punto!
-Joseph Marinaccio -Joseph Marinaccio
Marinaccio Family Design Marinaccio Family Design
Thank you. Salamat.
Is there a way to force the currency to be a specific one? Mayroon bang paraan upang pilitin ang pera ay isang tiyak na isa? Just because some has different regional settings it does not change the fact that a price is listed in (for example)pound. Just dahil ang ilan ay may iba't-ibang rehiyon na setting na ito ay hindi baguhin ang katunayan na ang presyo ay nakalista sa (halimbawa) pound.
You can provide IFormatProvider. Maaari kang magbigay ng IFormatProvider. In this case you can do something like this Sa kasong ito maaari mong gawin sa isang bagay tulad nito
using System.Globalization; gamit System.Globalization;
decimal = moneyValue = 100.00m; decimal = moneyValue = 100.00m;
string output = String.Format(CultureInfo.CurrentUICulture, “{0:C}”, moneyValue); string output = String.Format (CultureInfo.CurrentUICulture, "(0: C)", moneyValue);
With the above approach you don't need to worry about culture specific format. Sa itaas paraan hindi mo na kailangan mag-alala tungkol sa kultura ng mga tiyak na format.
use this method gamitin ang pamamaraan na ito
public static string formatmoney(Decimal d) public static string formatmoney (Desimal d)
{ (
return String.Format(CultureInfo.CreateSpecificCulture(”en-us”), “{0:C}”, d); bumalik String.Format (CultureInfo.CreateSpecificCulture ( "en-us"), "(0: C)", d);
} )