mushtariy

Mushtariy

Posted on August 17, 2024

Formatlash

C# dasturlash tilidaformatlash turli usullarda oshiriladi, eng ko'p ishlatiladigan usullardan biri String.Format va interpolation($ belgisi yordamida) ishlatiladi.

String.Format ga misol;

int yosh = 14;
double kasrSon = 12.2;
string ism = "Mushtariy";
string natija = String.Format{"Mening yoshim {0},/nMen kiritgan kasr {1},/nMening ismim {2}", yosh, kasrSon, ism};
Console.WriteLine(natija);

Enter fullscreen mode Exit fullscreen mode

Formatlash yordamida sonlarni ko'rinishini o'zgartirish mumkin.

Bu misolda {0:C} format kodi 'C' {Currency} yordam beradi;

double narx = 1234.56;
string nar = String.Format("Narx: {0:C}", narx);
Console.WriteLine(nar);
Enter fullscreen mode Exit fullscreen mode

sonlarni xona bo'yicha formatlash

int son = 42;
string ff = String.Format("Son: {0:D5}", son);
Console.WriteLine(ff);
Enter fullscreen mode Exit fullscreen mode

Foiz formatlash
{0:P}formatda yoziladi

double foiz = 0.875;
string son = String.Format("Foiz: {0:P2}", foiz);
Console.WriteLine(son);

Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
mushtariy
Mushtariy

Posted on August 17, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

String methods
programming String methods

August 24, 2024

Formatlash
programming Formatlash

August 17, 2024

Input
programming Input

August 9, 2024