[c#]代码库
public class ScienceCount
{
public static string KXJSF ( double num )
{
double bef = System.Math.Abs ( num );
int aft = 0;
while ( bef >= 10 || ( bef < 1 && bef != 0 ) )
{
if ( bef >= 10 )
{
bef = bef / 10;
aft++;
}
else
{
bef = bef * 10;
aft--;
}
}
return string.Concat ( num >= 0 ? "" : "-", ReturnBef ( bef ), "E", ReturnAft ( aft ) );
}
///
/// 有效数字的处理
///
/// 有效数字
/// 三位有效数字,不足则补零
public static string ReturnBef ( double bef )
{
if ( bef.ToString() != null )
{
char[] arr = bef.ToString().ToCharArray();
switch ( arr.Length )
{
case 1:
case 2:
return string.Concat ( arr[0], ".", "00" );
break;
case 3:
return string.Concat ( arr[0] + "." + arr[2] + "0" );
break;
default:
return string.Concat ( arr[0] + "." + arr[2] + arr[3] );
break;
}
}
else
return "000";
}
///
/// 幂的处理
///
/// 幂数
/// 三位幂数部分,不足则补零
public static string ReturnAft ( int aft )
{
if ( aft.ToString() != null )
{
string end;
char[] arr = System.Math.Abs ( aft ).ToString().ToCharArray();
switch ( arr.Length )
{
case 1:
end = "0" + arr[0];
break;
case 2:
end = arr[0].ToString() + arr[1];
break;
default:
end = System.Math.Abs ( aft ).ToString();
break;
}
return string.Concat ( aft >= 0 ? "+" : "-", end );
}
else
return "+00";
}
}
by: 发表于:2018-01-15 09:54:26 顶(0) | 踩(0) 回复
??
回复评论