Formatlash
Mushtariy
Posted on August 17, 2024
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);
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);
sonlarni xona bo'yicha formatlash
int son = 42;
string ff = String.Format("Son: {0:D5}", son);
Console.WriteLine(ff);
Foiz formatlash
{0:P}formatda yoziladi
double foiz = 0.875;
string son = String.Format("Foiz: {0:P2}", foiz);
Console.WriteLine(son);
💖 💪 🙅 🚩
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
programming Mastering C# Fundamentals: A Beginner’s Journey into .NET Development
September 19, 2024