Must Know Issue: Basics of String Format in .Net
Numeric Format
double dValue = 55000.54987D;
//displaying number in different formats
Response.Write("Currency Format: " + dValue.ToString("C") + "
");
Response.Write("Scientific Format: " + dValue.ToString("E") + "
");
Response.Write("Percentage Format: " + dValue.ToString("P") + "
");
/* OUTPUT */
Currency Format: $55,000.55
Scientific Format: 5.500055E+004
Percentage Format: 5,500,054.99 %
Getting Culture Specific String
double dValue = 55000.54987D;
//You can Remove this line
Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
//This line will automatically detect client culture
//and display data accordingly
//Here culture has forcefully changed to german to
//view difference in output
CultureInfo ci = Thread.CurrentThread.CurrentCulture;
//displaying number in different formats
Response.Write("Currency Format: " + dValue.ToString("C",ci) + "
");
Response.Write("Scientific Format: " + dValue.ToString("E",ci) + "
");
Response.Write("Percentage Format: " + dValue.ToString("P",ci) + "
");
/* OUTPUT */
Currency Format: 55.000,55 €
Scientific Format: 5,500055E+004
Percentage Format: 5.500.054,99%
No comments:
Post a Comment