# ToString截取字符串的用法

double less1BitDouble = 343392590725.6758; string less1BitDoubleStrG = less1BitDouble.ToString("G");   //"343392590725.676" string less1BitDoubleStrF = less1BitDouble.ToString("F");   //"343392590725.68" string less1BitDoubleStrF6 = less1BitDouble.ToString("F6"); //"343392590725.676000"

double less1BitDouble = 343392590725.6758; string less1BitDoubleStrG = less1BitDouble.ToString("G");   //"343392590725.676" string less1BitDoubleStrF = less1BitDouble.ToString("F");   //"343392590725.68" string less1BitDoubleStrF6 = less1BitDouble.ToString("F6"); //"343392590725.676000"

string test1=test.ToString("F");//结果为343392590725.68，保留小数点后两位

string test2=test.ToString("F6");//结果为343392590725.675800，保留小数点后6位，不足用0补上

string test3=test.ToString("G");//结果为343392590725.6758，默认输出原先的，多余double最多15个数字

string test4=test.ToString("0.00")//结果为343392590725.68，保留小数点后两位

1 2 3 4

double less1BitDouble = 343392590725.6758; string less1BitDoubleStrG = less1BitDouble.ToString("G");   //"343392590725.676" string less1BitDoubleStrF = less1BitDouble.ToString("F");   //"343392590725.68" string less1BitDoubleStrF6 = less1BitDouble.ToString("F6"); //"343392590725.676000"

1 2 3 4

double smallValDouble = 1234.567890; string smallValDoubleStrG = smallValDouble.ToString("G");   //1234.56789 string smallValDoubleStrF = smallValDouble.ToString("F");   //1234.57 string smallValDoubleStrF6 = smallValDouble.ToString("F6"); //1234.567890

F：默认是2位小数点

F6：输出小数点后6位，不够的话用0补齐

G：默认输出原先的，保留小数点后面的位数（对于double默认是最多15个，详见：標準數值格式字串）。

460 篇文章37 人订阅

0 条评论

2277

832

3051

23910

1323

2217

19410

1702

2885

2704