0
How can Formatting and Retrieving Information in c# ?
1 Resposta
0
using System;
class Picts
{
public static void Main()
{
int var1 = 1234;
float var2 = 12.34F;
// Zero formatter
Console.WriteLine(â\nZero...â);
Console.WriteLine(â{0} -->{0:0000000}â, var1);
Console.WriteLine(â{0} -->{0:0000000}â, var2);
// Space formatter
Console.WriteLine(â\nSpace...â);
Console.WriteLine(â{0} -->{0:0####}<--â, var1);
Console.WriteLine(â{0} -->{0:0####}<--â, var2);
// Group separator and multiplier (,)
Console.WriteLine(â\nGroup Multiplier...â);
Console.WriteLine(â{0} -->{0:0,,}<--â, 1000000);
Console.WriteLine(âGroup Separator...â);
Console.WriteLine(â{0} -->{0:##,###,##0}<--â, 2000000);
Console.WriteLine(â{0} -->{0:##,###,##0}<--â, 3);
// Percentage formatter
Console.WriteLine(â\nPercentage...â);
Console.WriteLine(â{0} -->{0:0%}<--â, var1);
Console.WriteLine(â{0} -->{0:0%}<--â, var2);
// Literal formatting
Console.WriteLine(â\nLiteral Formatting...â);
Console.WriteLine(â{0} -->{0:âMy Number: â0}<--â, var1);
Console.WriteLine(â{0} -->{0:âMy Number: â0}<--â, var2);
Console.WriteLine(â\n{0} -->{0:Mine: 0}<--â, var1);
Console.WriteLine(â{0} -->{0:Mine: 0}<--â, var2);
}
}
// Output
Zero...
1234 -->0001234
12.34 -->0000012
Space...
1234 -->01234<--
12.34 -->00012<--
Group Multiplier...
1000000 -->1<--
Group Separator...
2000000 -->2,000,000<--
3 -->3<--
Percentage...
1234 -->123400%<--
12.34 -->1234%<--
Literal Formatting...
1234 -->My Number: 1234<--
12.34 -->My Number: 12<--
1234 -->Mine: 1234<--
12.34 -->Mine: 12<--