using System;
using System.Collections.Generic;
using System.Text;
namespace 遍历数组
{
class Program
{
static void Main(string[] args)
{
int passed=0;
int[] score = new int[] { 98, 76, 87, 65, 55, 68, 57, 84, 91, 100, 58, 76 };
foreach (int x in score )
if (x >= 60)
{
passed++;
Console.Write("{0,-4}",x );
}
Console.WriteLine("\n及格率:{0:p}",(double )passed /score .Length );
}
}
}
最后一个输出中,{0:p}是什么意思?
0是参数索引,P应该是格式中的%
string.Format("{0:P}", 0.24583) 结果为:24.58% (默认保留百分的两位小数)
昨天给你的msdn链接白给了?一个页面,难道你不能完整看一下么?
https://msdn.microsoft.com/zh-cn/library/dwhawy9k.aspx
注意,你光写一个P保留几位小数由NumberFormatInfo.PercentDecimalDigits指定。