Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.2 00000001.20
- .2 00000000.20
- -.2 -0000000.20
- 12 00000012.00
- 0 00000000.00
- -0 00000000.00
- 12.555 00000012.55
- {0:00000000.00;0:0000000.00;0:00000000.00}
- string format = "{0:00000000.00;-0000000.00}";
- Console.WriteLine(string.Format(format, 1.2));
- Console.WriteLine(string.Format(format, .2));
- Console.WriteLine(string.Format(format, -.2));
- Console.WriteLine(string.Format(format, 12.0));
- Console.WriteLine(string.Format(format, -0.0));
- Console.WriteLine(string.Format(format, 12.555));
- {position:postive format;negative format;zero format}
- string.Format("{0:00000000.00}", 1.2)
- double d = -12.365;
- string s = d.ToString("0:00000000.00");//-0:00000012.37
- string sOut = d.ToString("00000000.00")//-00000012.37
- using System;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication3
- {
- class Program
- {
- static void Main(string[] args)
- {
- Func<double, string> toFixedWidth = (d) => {
- return string.Format("{0:00000000.00;-0000000.00}", d);
- };
- foreach (var d in new double[] { 1.2, 0.2, -0.2, 12, 0, -0, 12.555 })
- {
- Console.WriteLine(toFixedWidth(d));
- }
- }
- }
- }
- 00000001,20
- 00000000,20
- -0000000,20
- 00000012,00
- 00000000,00
- 00000000,00
- 00000012,56
- Press any key to continue . . .
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement